<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=dylanschell" rel="nofollow">Dylan Schell</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-4338?redirect=false" rel="nofollow">SPR-4338</a></strong> and commented</p>
<p dir="auto">When trying to define components through the component-scan feature, one of our classes was stubbornly refusing the be published in the context. after some debugging it seemed that it was "failing" in the ClassPathScanningCandidateComponentProvider.isCandidateComponent()</p>
<p dir="auto">beanDefinition.getMetadata().isConcrete() is properly returning true, but the beanDefinition.getMetadata().isIndependent() is returning false.</p>
<p dir="auto">as an aside, there seems to be no logging whatsoever in these classes, making it hard to see which components get published.<br>
}</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.5.1</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="398084522" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9003" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9003/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9003">#9003</a> component scanning incorrectly excludes classes (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=haroon.rafique" rel="nofollow">Haroon Rafique</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-4324?redirect=false" rel="nofollow">SPR-4324</a></strong> and commented</p>
<p dir="auto">The version bump from 2.5 to 2.5.1 breaks component scanning for me. Symptoms are that lots of beans annotated with <code class="notranslate">@Component</code> are being skipped for inclusion as beans. After digging through the code, I think the following commit is the culprit:</p>
<p dir="auto"><a href="http://fisheye1.cenqua.com/changelog/springframework?cs=MAIN:jhoeller:20080107164524" rel="nofollow">http://fisheye1.cenqua.com/changelog/springframework?cs=MAIN:jhoeller:20080107164524</a></p>
<p dir="auto">The commit message says:</p>
<p dir="auto">added "getEnclosingClassName()", "hasEnclosingClass()" and "isIndependent()" methods to ClassMetadata interface; ClassPathScanningCandidateComponentProvider ("context:component-scan") ignores non-static inner and local classes</p>
<p dir="auto">I am not sure why beanDefinition.getMetadata().isIndependent() is returning false for my classes. The scenario is as follows:</p>
<p dir="auto">MyBroker has <code class="notranslate">@Component</code> annotation. MyBroker uses a class MyService (regular instantiation) using something like:<br>
MyService service = new MyService()<br>
MyService, in turn, is the class which DOES have a local inner class. I think the bug is in identifying MyBroker as having an inner class. It should not identify MyBroker as having an inner class (since it doesn't have one).</p>
<p dir="auto">ClassMetaDataReadingVisitor.java has the following method:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public boolean isIndependent() {
	return (this.enclosingClassName == null || this.independentInnerClass);
}"><pre class="notranslate"><code class="notranslate">public boolean isIndependent() {
	return (this.enclosingClassName == null || this.independentInnerClass);
}
</code></pre></div>
<p dir="auto">In that method, while trying to see if MyBroker is a candidate, enclosingClassName is set to MyService.</p>
<p dir="auto">I think this needs a quick fix.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.5.1</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/13270/spring-2.5.1-component-scanning-inner-class-bug-SPR-4324.zip" rel="nofollow">spring-2.5.1-component-scanning-inner-class-bug-SPR-4324.zip</a> (<em>4.92 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="398085546" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9134" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9134/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9134">#9134</a> Weird autowiring bug (<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="398084711" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9029" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9029/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9029">#9029</a> context:annotation-config skips classes using inner classes in 2.5.1 (<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="398086023" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9204" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9204/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9204">#9204</a> bug in context:component-scan when class have inner classes  (<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="398084640" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9017" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9017/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9017">#9017</a> Classes with Inner classes are not recognized as independent classes themselves (<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="398087253" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9363" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9363/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9363">#9363</a> <code class="notranslate">@Component</code> annotated class that contains a private non-static inner class not considered as candidate component because  beanDefinition.getMetadata().isIndependent() returns false (<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="398085562" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9136" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9136/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9136">#9136</a> Component-scan does not work correctly for annotated service SimpleJdbcClinic in sample 'petclinic'</li>
</ul>