<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=ferrix" rel="nofollow">Riccardo</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2861?redirect=false" rel="nofollow">SPR-2861</a></strong> and commented</p>
<p dir="auto">All the beans defined in any configuration file are visible from the whole project. t would be useful to be able to limit the visibility of a bean to only the file where it is defined. Something like &lt;bean-local ... &gt;. I have looked in the forum and jira and I couldn't find anything like this.</p>
<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="398104986" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11829" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11829/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11829">#11829</a> Support <code class="notranslate">@Bean</code> method visibility (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=eberhardwolff" rel="nofollow">Eberhard Wolff</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7170?redirect=false" rel="nofollow">SPR-7170</a></strong> and commented</p>
<p dir="auto">In JavaConfig beans created by protected methods with <code class="notranslate">@Bean</code> annotation had visibility inside the <code class="notranslate">@Configuration</code> class only but were not exported into the global <code class="notranslate">ApplicationContext</code> and therefore cannot be referenced from there or other <code class="notranslate">@Configuration</code> annotated classes:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@Configuration
public class MyConfiguration {
  @Bean
  public ABean globallyVisible() { ... }

  @Bean
  protected ABean visibleOnlyInThisClass() { ... }
}"><pre class="notranslate"><span class="pl-c1">@</span><span class="pl-c1">Configuration</span>
<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">MyConfiguration</span> {
  <span class="pl-c1">@</span><span class="pl-c1">Bean</span>
  <span class="pl-k">public</span> <span class="pl-smi">ABean</span> <span class="pl-en">globallyVisible</span>() { ... }

  <span class="pl-c1">@</span><span class="pl-c1">Bean</span>
  <span class="pl-k">protected</span> <span class="pl-smi">ABean</span> <span class="pl-en">visibleOnlyInThisClass</span>() { ... }
}</pre></div>
<p dir="auto">This is great to structure large configuration because beans can be hidden. Bring that feature back please.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0 GA, 3.0.1, 3.0.2</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="398111454" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12839" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12839/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12839">#12839</a> Revised support for bean definition visibility and overriding (<em><strong>"is depended on by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398073079" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7548" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7548/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7548">#7548</a> Allow to restrict the visibility of beans to a file (<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="398094306" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10325" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10325/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10325">#10325</a> Consider using javassist for proxy generation</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398110303" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12637" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12637/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12637">#12637</a> Support profile exclusivity and/or bean definition finality</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398082106" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/8713" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/8713/hovercard" href="https://github.com/spring-projects/spring-framework/issues/8713">#8713</a> Exporting / Importing beans across ApplicationContexts</li>
</ul>
<p dir="auto">27 votes, 22 watchers</p>