<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=baronludwig" rel="nofollow">Marc Ludwig</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-3873?redirect=false" rel="nofollow">SPR-3873</a></strong> and commented</p>
<p dir="auto">I have been using both LTW and Component scanning using 2.1 M3. (This is actually for testing as we use Compile Time Weaving in the built application).<br>
Just tried with 2.1 M4, and it appears that duplicate bean definitions are being generated, causing exceptions.</p>
<p dir="auto">The XML config is as follows:<br>
[code]</p>
<p dir="auto">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</p>
<p dir="auto">&lt;beans xmlns="<a href="http://www.springframework.org/schema/beans" rel="nofollow">http://www.springframework.org/schema/beans</a>"<br>
xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance</a>"<br>
xmlns:util="<a href="http://www.springframework.org/schema/util" rel="nofollow">http://www.springframework.org/schema/util</a>"<br>
xmlns:context="<a href="http://www.springframework.org/schema/context" rel="nofollow">http://www.springframework.org/schema/context</a>"<br>
xmlns:tx="<a href="http://www.springframework.org/schema/tx" rel="nofollow">http://www.springframework.org/schema/tx</a>"<br>
xmlns:jee="<a href="http://www.springframework.org/schema/jee" rel="nofollow">http://www.springframework.org/schema/jee</a>"<br>
xsi:schemaLocation="<br>
<a href="http://www.springframework.org/schema/beans" rel="nofollow">http://www.springframework.org/schema/beans</a> <a href="http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" rel="nofollow">http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</a><br>
<a href="http://www.springframework.org/schema/util" rel="nofollow">http://www.springframework.org/schema/util</a> <a href="http://www.springframework.org/schema/util/spring-util.xsd" rel="nofollow">http://www.springframework.org/schema/util/spring-util.xsd</a><br>
<a href="http://www.springframework.org/schema/tx" rel="nofollow">http://www.springframework.org/schema/tx</a> <a href="http://www.springframework.org/schema/tx/spring-tx.xsd" rel="nofollow">http://www.springframework.org/schema/tx/spring-tx.xsd</a><br>
<a href="http://www.springframework.org/schema/context" rel="nofollow">http://www.springframework.org/schema/context</a> <a href="http://www.springframework.org/schema/context/spring-context-2.1.xsd" rel="nofollow">http://www.springframework.org/schema/context/spring-context-2.1.xsd</a><br>
<a href="http://www.springframework.org/schema/jee" rel="nofollow">http://www.springframework.org/schema/jee</a> <a href="http://www.springframework.org/schema/jee/spring-jee.xsd%22%3E" rel="nofollow">http://www.springframework.org/schema/jee/spring-jee.xsd"&gt;</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;context:load-time-weaver aspectj-weaving=&quot;on&quot;/&gt;

&lt;context:component-scan  annotation-config=&quot;true&quot; base-package=&quot;base.package&quot;/&gt;"><pre class="notranslate"><code class="notranslate">&lt;context:load-time-weaver aspectj-weaving="on"/&gt;

&lt;context:component-scan  annotation-config="true" base-package="base.package"/&gt;
</code></pre></div>
<p dir="auto">&lt;/beans&gt;<br>
[/code]</p>
<p dir="auto">If any <code class="notranslate">@Component</code> is picked up by the scanning then the following exception is thrown:<br>
[code]<br>
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [base.package.domain.ObjectWithDependencies] for bean with name 'objectWithDependencies' defined in null: problem with class file or dependent class; nested exception is java.lang.LinkageError: duplicate class definition:base/package/domain/ObjectWithDependencies<br>
[/code]</p>
<p dir="auto">Is it now incorrect to combine the component scanning and load time weaving, or is this unexpected behaviour?</p>
<p dir="auto">Regards</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.1 M4</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/13019/spring-ltw-test.zip" rel="nofollow">spring-ltw-test.zip</a> (<em>6.42 kB</em>)</li>
</ul>
<p dir="auto">1 votes, 2 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=abeani" rel="nofollow">Andreas Benneke</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7900?redirect=false" rel="nofollow">SPR-7900</a></strong> and commented</p>
<p dir="auto">Annotation driven injection on public methods specified in a non-public base classes does not work, because Java generates bridge methods for the subclass which are not ignored by Spring (as they should IMHO).</p>
<p dir="auto">Example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/* not public! */ class Base {

	@Resource
	public void setResource(Injectable injectable) {
           ...
	}
}

@Component
public class Target extends Base {

}"><pre class="notranslate"><code class="notranslate">/* not public! */ class Base {

	@Resource
	public void setResource(Injectable injectable) {
           ...
	}
}

@Component
public class Target extends Base {

}
</code></pre></div>
<p dir="auto">Same applies to <code class="notranslate">@Autowired</code>.</p>
<p dir="auto">The attached maven project demonstrates this.</p>
<p dir="auto">Workarounds: Use field injection, re-declare the method(s) in the subclass or make the base class public.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/17536/injection-test.zip" rel="nofollow">injection-test.zip</a> (<em>3.10 kB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/18361/mylyn-context.zip" rel="nofollow">mylyn-context.zip</a> (<em>4.65 kB</em>)</li>
</ul>
<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="398112881" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13080" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13080/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13080">#13080</a> AutowiredAnnotationBeanPostProcessor should ignore bridge methods when looking for annotations (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398114331" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13302" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13302/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13302">#13302</a> Bridged method detection leads to false positive detection of autowired annotations</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398174302" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/17096" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/17096/hovercard" href="https://github.com/spring-projects/spring-framework/issues/17096">#17096</a> <code class="notranslate">@Resource</code> injection broken under spring-framework &gt; 4.1.0</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398174348" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/17101" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/17101/hovercard" href="https://github.com/spring-projects/spring-framework/issues/17101">#17101</a> Consistent bridge method handling in annotation post-processors</li>
</ul>