<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=colin.sampaleanu" rel="nofollow">Colin Sampaleanu</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2285?redirect=false" rel="nofollow">SPR-2285</a></strong> and commented</p>
<p dir="auto">The bean factory and application context contract clearly states (as per our docs) that within one definition xml file a bean id must be unique.</p>
<p dir="auto">This is enforced by the XML parser when using the "id" attribute exclusively because this is flagged as an XML IDREF attribute. However, by combining the use of the id attribute and the name attribute, or just using the name attribute exclusively, it is possible to have 2 or more bean definitions in the same xml file with the same id. This is silently accepted with the last bean definition winning out.</p>
<p dir="auto">The bean definition reader must basically track ids, however they are supplied, and enforce the same semantics from usage of the "name" attribute as from usage of the "id" attribute.</p>
<p dir="auto">A related question is what should happen in the case of &lt;import&gt;? An argument could be made either way here.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0 RC2</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/11870/spring2285_testcase_and_patch.zip" rel="nofollow">spring2285_testcase_and_patch.zip</a> (<em>2.67 kB</em>)</li>
</ul>
<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-7888?redirect=false" rel="nofollow">SPR-7888</a></strong> and commented</p>
<p dir="auto">Equivalent to context:spring-configured/</p>
<p dir="auto">Because <code class="notranslate">@Configuration</code> classes don't produce bean definitions in quite the same way that XML configuration files do, an annotation-based <code class="notranslate">@SpringConfigured</code> annotation must work differently than context:spring-configured/.  Consider the following approach:</p>
<p dir="auto"><code class="notranslate">@Configurationpublic</code> class SpringConfiguredBeans {</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@SpringConfigured
public void someEntity(MyEntity entity) {
    entity.setRepository(myRepository());        
}

@Bean
public MyRepository myRepository() {
    return new MyRepository(dataSource());
}

// ...}"><pre class="notranslate"><code class="notranslate">@SpringConfigured
public void someEntity(MyEntity entity) {
    entity.setRepository(myRepository());        
}

@Bean
public MyRepository myRepository() {
    return new MyRepository(dataSource());
}

// ...}
</code></pre></div>
<hr>
<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="398111214" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12790" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12790/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12790">#12790</a> SpringConfiguredBeanDefinitionParser (aop:spring-configured) (<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="398111223" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12792" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12792/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12792">#12792</a> SpringConfiguredBeanDefinitionParser (context:spring-configured) (<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="398106528" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12078" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12078/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12078">#12078</a> Support Java-Based Application Configuration</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/22e37aac444812eab6982a9f658d70656dd6a729/hovercard" href="https://github.com/spring-projects/spring-framework/commit/22e37aac444812eab6982a9f658d70656dd6a729"><tt>22e37aa</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/d35620511e8304421929e89ed4d13d82d5f40219/hovercard" href="https://github.com/spring-projects/spring-framework/commit/d35620511e8304421929e89ed4d13d82d5f40219"><tt>d356205</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/4318ccd9d519525a674a61ddf80b11f8bec29426/hovercard" href="https://github.com/spring-projects/spring-framework/commit/4318ccd9d519525a674a61ddf80b11f8bec29426"><tt>4318ccd</tt></a></p>
<p dir="auto">1 votes, 2 watchers</p>