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

Closed
spring-issuemaster opened this issue Oct 18, 2014 · 1 comment
Closed

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

spring-issuemaster opened this issue Oct 18, 2014 · 1 comment
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster 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:

http://docs.spring.io/spring-javaconfig/docs/1.0-m2/reference/html/bean-visibility.html

This documentation does not appear to exist in:

http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/beans.html#beans-factorybeans-annotations

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

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster 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.

Juergen

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.