Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document method visibility rules for @Bean methods [SPR-12345] #16950

spring-projects-issues opened this issue Oct 18, 2014 · 1 comment


Copy link

@spring-projects-issues spring-projects-issues commented Oct 18, 2014

Bob Tiernay opened SPR-12345 and commented

There used to be documentation in the JavaConfig project that discussed the effect of method visibility on bean scope:

This documentation does not appear to exist in:

However, there is an example in that section regarding a privateInstance but the semantics are still undefined. I am still unclear what effect marking an @Bean method private has. I was hoping it would make it private to the @Configuration as that could be very useful in certain circumstances.

Nevertheless, it would be extremely useful to document these semantics.

Affects: 4.1.1

Referenced from: commits f58e1db

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 7, 2015

Juergen Hoeller commented

I've added a note on @Bean method visibility to the reference documentation now.

In the end, the declared Java language visibility has no immediate impact on the resulting bean definition. A private @Bean method may still get obtained and autowired in other places.

Actually, the most important part is that @Bean methods must not be declared as private or final in regular @Configuration classes since those methods need to be overridable in order to redirect direct method calls back to the container. With @Bean methods on non-@Configuration classes and static @Bean methods anywhere, no such limitations apply.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants