<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=xarx" rel="nofollow">Xarx</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8343?redirect=false" rel="nofollow">SPR-8343</a></strong> and commented</p>
<p dir="auto">What happens:<br>
I have a field denoted by <code class="notranslate">@Autowire</code>. There is one <code class="notranslate">@Primary</code> bean candidate for the field, the other candidates are marked as <code class="notranslate">@Lazy</code>. However, even in this case, when a primary candidate is available, all lazy candidates are instantiated during the candidate lookup process.</p>
<p dir="auto">What should happen:<br>
When a primary candidate exists, it should be chosen without instantiation of other lazy-init candidates.</p>
<p dir="auto">I tried to use the <code class="notranslate">@Lazy</code> annotation to mark beans that are not to be instantiated unless realy used by the application. But this doesn't work currently.</p>
<p dir="auto">More details:<br>
Spring's (org.springframework.beans.factory.support) DefaultListBeanFactory.doResolveDependency() internally calls findAutowireCandidates(). findAutowireCandidates() instantiates all candidate beans, but the determination whether there exists a primary candidate is done only later in doResolveDependency() - which is too late. This determination should be done earlier in findAutowireCandidates(), before the other candidates are instantiated.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</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="398112342" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12992" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12992/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12992">#12992</a> Lazy-init beans are unnecessarily created during the candidate determination process (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">4 votes, 4 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=nazin" rel="nofollow">Nazin Alexander</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5254?redirect=false" rel="nofollow">SPR-5254</a></strong> and commented</p>
<p dir="auto">public abstract class A {<br>
private Object service;</p>
<p dir="auto">public void setService(Object service) {<br>
this.service = service;<br>
}</p>
<p dir="auto">public Object getService() {<br>
return service;<br>
}</p>
<p dir="auto">}</p>
<p dir="auto">public class B extends A{</p>
<p dir="auto"><code class="notranslate">@Override</code><br>
public MyService getService() {<br>
return (MyService) super.getService();<br>
}<br>
}</p>
<p dir="auto">&lt;bean id="myService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean" scope="singleton" lazy-init="true"&gt;<br>
&lt;property name="serviceUrl" value="${protocol_type}://${server_ip}:${server_port}/application/javaservice/service"/&gt;<br>
&lt;property name="serviceInterface" value="com.xxx.yyy.ServiceInt"/&gt;<br>
&lt;property name="httpInvokerRequestExecutor" ref="commonsHttpInvokerRequestExecutor"/&gt;<br>
&lt;/bean&gt;<br>
&lt;!--****************************************************************************************************--&gt;<br>
&lt;bean id="dao" class="org.springframework.aop.framework.ProxyFactoryBean" scope="singleton" lazy-init="true"&gt;<br>
&lt;property name="target"&gt;<br>
&lt;bean class="com.xxxyyy.zzz.B"&gt;<br>
&lt;property name="service" ref="myService"/&gt;<br>
&lt;/bean&gt;<br>
&lt;/property&gt;<br>
&lt;property name="interceptorNames"&gt;<br>
&lt;list&gt;<br>
&lt;value&gt;exceptionIntercepter&lt;/value&gt;<br>
&lt;/list&gt;<br>
&lt;/property&gt;<br>
&lt;/bean&gt;<br>
&lt;/beans&gt;<br>
When load application error: Bean property 'service' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.5.5</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="398071993" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7415" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7415/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7415">#7415</a> Dealing with covariant properties in CachedIntrospectionResults (<em><strong>"duplicates"</strong></em>)</li>
</ul>