<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=cbeams" rel="nofollow">Chris Beams</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8182?redirect=false" rel="nofollow">SPR-8182</a></strong> and commented</p>
<p dir="auto">Based on decisions made in other subtasks of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398111402" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12830" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12830/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12830">#12830</a>.</p>
<hr>
<p dir="auto">This issue is a sub-task of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398111402" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12830" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12830/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12830">#12830</a></p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398110788" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12711" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12711/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12711">#12711</a> Decide what to do with 'local' attribute in beans: namespace (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/50dfa037d005639a871b804da2488b74b466db25/hovercard" href="https://github.com/spring-projects/spring-framework/commit/50dfa037d005639a871b804da2488b74b466db25"><tt>50dfa03</tt></a></p>
<p dir="auto">1 votes, 4 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=skajotde" rel="nofollow">Kamil</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9092?redirect=false" rel="nofollow">SPR-9092</a></strong> and commented</p>
<p dir="auto">I implement contributions for my application and I found inconsistent behaviour for Provider/ObjectFactory. There are defined classes for different contributions:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@Contribute(&quot;rest&quot;)
@Named(&quot;bean-contrib2a&quot;)
public class Contrib2A implements ContribRest { ... }

@Contribute(&quot;rest&quot;)
@Named(&quot;bean-contrib2b&quot;)
public class Contrib2B { ... }

@Contribute(&quot;non-rest&quot;)
@Named(&quot;bean-contrib3a&quot;)
public class Contrib3A implements ContribRest { ... }

@Contribute(&quot;non-rest&quot;)
@Named(&quot;bean-contrib3b&quot;)
public class Contrib3B { ... }"><pre class="notranslate"><code class="notranslate">@Contribute("rest")
@Named("bean-contrib2a")
public class Contrib2A implements ContribRest { ... }

@Contribute("rest")
@Named("bean-contrib2b")
public class Contrib2B { ... }

@Contribute("non-rest")
@Named("bean-contrib3a")
public class Contrib3A implements ContribRest { ... }

@Contribute("non-rest")
@Named("bean-contrib3b")
public class Contrib3B { ... }
</code></pre></div>
<p dir="auto">Code to show injecting scenario looks like that:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@Named(&quot;applicationRest&quot;)
public class ApplicationRest extends Application {

    private List&lt;ContribRest&gt; contrib2;
    private List&lt;ContribRest&gt; contrib4;

    private ObjectFactory&lt;List&lt;ContribRest&gt;&gt; ofContrib2;
    private ObjectFactory&lt;List&lt;ContribRest&gt;&gt; ofContrib4;

    private Provider&lt;List&lt;ContribRest&gt;&gt; pvdContrib2;
    private Provider&lt;List&lt;ContribRest&gt;&gt; pvdContrib4;

    @Inject
    public void setContrib2(@Contribute(&quot;rest&quot;) List&lt;ContribRest&gt; contrib2) {
        this.contrib2 = contrib2;
    }

    @Autowired(required = false)
    public void setContrib4(@Contribute(&quot;other&quot;) List&lt;ContribRest&gt; contrib4) {
        this.contrib4 = contrib4;
    }

    @Inject
    public void setOfContrib2(@Contribute(&quot;rest&quot;) ObjectFactory&lt;List&lt;ContribRest&gt;&gt; ofContrib2) {
        this.ofContrib2 = ofContrib2;
    }

    @Autowired(required = false)
    public void setOfContrib4(@Contribute(&quot;other&quot;) ObjectFactory&lt;List&lt;ContribRest&gt;&gt; ofContrib4) {
        this.ofContrib4 = ofContrib4;
    }

    @Inject
    public void setPvdContrib2(@Contribute(&quot;rest&quot;) Provider&lt;List&lt;ContribRest&gt;&gt; pvdContrib2) {
        this.pvdContrib2 = pvdContrib2;
    }

    @Autowired(required = false)
    public void setPvdContrib4(@Contribute(&quot;other&quot;) Provider&lt;List&lt;ContribRest&gt;&gt; pvdContrib4) {
        this.pvdContrib4 = pvdContrib4;
    }"><pre class="notranslate"><code class="notranslate">@Named("applicationRest")
public class ApplicationRest extends Application {

    private List&lt;ContribRest&gt; contrib2;
    private List&lt;ContribRest&gt; contrib4;

    private ObjectFactory&lt;List&lt;ContribRest&gt;&gt; ofContrib2;
    private ObjectFactory&lt;List&lt;ContribRest&gt;&gt; ofContrib4;

    private Provider&lt;List&lt;ContribRest&gt;&gt; pvdContrib2;
    private Provider&lt;List&lt;ContribRest&gt;&gt; pvdContrib4;

    @Inject
    public void setContrib2(@Contribute("rest") List&lt;ContribRest&gt; contrib2) {
        this.contrib2 = contrib2;
    }

    @Autowired(required = false)
    public void setContrib4(@Contribute("other") List&lt;ContribRest&gt; contrib4) {
        this.contrib4 = contrib4;
    }

    @Inject
    public void setOfContrib2(@Contribute("rest") ObjectFactory&lt;List&lt;ContribRest&gt;&gt; ofContrib2) {
        this.ofContrib2 = ofContrib2;
    }

    @Autowired(required = false)
    public void setOfContrib4(@Contribute("other") ObjectFactory&lt;List&lt;ContribRest&gt;&gt; ofContrib4) {
        this.ofContrib4 = ofContrib4;
    }

    @Inject
    public void setPvdContrib2(@Contribute("rest") Provider&lt;List&lt;ContribRest&gt;&gt; pvdContrib2) {
        this.pvdContrib2 = pvdContrib2;
    }

    @Autowired(required = false)
    public void setPvdContrib4(@Contribute("other") Provider&lt;List&lt;ContribRest&gt;&gt; pvdContrib4) {
        this.pvdContrib4 = pvdContrib4;
    }
</code></pre></div>
<p dir="auto">Injection finish with that result:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="INFO contrib2=[Contrib2A@51a19458] -
INFO contrib4=null
ERROR ofContrib2=No unique bean of type [java.lang.Object] is defined: expected single matching bean but found 2: [bean-contrib2b, bean-contrib2a]
INFO ofContrib4=null
ERROR pvdContrib2=No unique bean of type [java.lang.Object] is defined: expected single matching bean but found 2: [bean-contrib2b, bean-contrib2a] - 
INFO pvdContrib4=null
"><pre class="notranslate"><code class="notranslate">INFO contrib2=[Contrib2A@51a19458] -
INFO contrib4=null
ERROR ofContrib2=No unique bean of type [java.lang.Object] is defined: expected single matching bean but found 2: [bean-contrib2b, bean-contrib2a]
INFO ofContrib4=null
ERROR pvdContrib2=No unique bean of type [java.lang.Object] is defined: expected single matching bean but found 2: [bean-contrib2b, bean-contrib2a] - 
INFO pvdContrib4=null

</code></pre></div>
<p dir="auto">Injecting list looks correct - classes with other contribution and type are filtered and only Contrib2A is injected.</p>
<p dir="auto">Unfortunately injecting Provider or ObjectFactory tries to inject List a not all beans for this list and it looks as a bug.</p>
<p dir="auto">Maybe you can provide alternative way to how can I provide this list with all instances contributed (scanned) without manually defining list in XML.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 GA</p>
<p dir="auto"><strong>Reference URL:</strong> <a href="http://forum.springsource.org/showthread.php?122488-Injecting-autowiring-collection-provider-to-implement-contribution" rel="nofollow">http://forum.springsource.org/showthread.php?122488-Injecting-autowiring-collection-provider-to-implement-contribution</a></p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398116707" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13669" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13669/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13669">#13669</a> javax.Provider Spring support doesn't work for collections (<em><strong>"duplicates"</strong></em>)</li>
</ul>