-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Support @Bean method visibility [SPR-7170] #11829
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
Comments
Eberhard Wolff commented As pointed out at https://www.blogger.com/comment.g?blogID=14001982&postID=1001503393511544614 the visibility needs to be defined more precisely. i.e. would a BeanPostProcessor / BeanFactoryPostProcessor be allowed to see it? |
Chris Beams commented There are a number of efforts that will require changes to the core container during the Spring 3.1 timeline, and it's conceivable that we could do something like this. However, doing so would add significant complexity, and I'm not yet sure it's worth it. This issue has a few votes already; I'd love to hear some specific use cases for this issue. How would it help you? How does the lack of such a feature visibility hurt you presently? I'm scheduling this for 3.1, just so it remains on the radar. In the meantime, let's hear what folks have to say. |
Chris Beams commented Assigning to 3.1 M2 for general tracking purposes. |
Oliver Drotbohm commented Actually the use case is quite obvious IMHO, but might be I am exposed to that kind of issues more that others. Enabling good application architecture you want to split up your app into subsystems that expose functionality (provided interface) expose what they need (required interface) and hide internals (the classical component notion). Currently you can only achieve this by using OSGi with e.g. Spring DM. There you expose only certain Spring beans and turn required OSGi services into Spring beans on the other side. Now let's imagine OSGi is overkill, we want to stick to a plain JavaSE, JavaEE environment, don't need dynamics, just want to enforce visibility at wiring time. With the visibility feature you could simply have something like this:
This way you create two beans that are managed by Spring, but cannot be referenced from other subsystems ore more strictly speaking from other configurations. I'd also argue they should not be candidates for autowiring. Only As simple classic example assume we have some |
Chris Beams commented Marking this issue as duplicated by #7548, which requests bean visibility control from an XML perspective. Any visibility solution implemented on the Java ( |
Chris Beams commented Slating this for review during the Spring 3.2 timeline. As mentioned before, this is a pretty significant chunk of work and potential complexity. I'd like to see additional votes and anecdotes regarding real-world need, and waiting for 3.2 gives that some time. 3.2 is also when we'll revisit the use of CGLIB throughout the framework, including its use in supporting We'll also look at other related issues like |
Eberhard Wolff commented I still think this is a valuable improvement. Recently the OSGi community even said that the service model is the most important part of OSGi. This would give a very similar approach I guess. Having said this you could also solve the issue by limiting the visibility of the classes / interfaces. If the configuration is in the same package as the implementation you can use default visibility for the non-public beans - they could not be accessed outside the package then. |
Andreas Benneke commented Here is another example based on our real world problem while migrating from XML to Java Our
Please note that
Translating this configuration to Java we ended up with something similar to this one:
To have all the Spring magic working on the
Both points are no big deal, but they require additional explanation and expose complexity we would prefer to hide. We would love to see any possibility to create the "inner"/"nested" beans in Java |
Bulk closing outdated, unresolved issues. Please, reopen if still relevant. |
A testcase where this is absolutely desirable is when creating custom starters. You want Spring autowiring magic within the scope of the starter, but not exposing all autconfiguration's beans to the context of the end client. |
I currently encountered another situation where this would be of great value: We are using spring-ws and would like to create multiple MessageDispatcherServlets with different URLs for different services. And each of these should be configured with their own EndpointMappings, EndpointInterceptors,... Currently each servlet sees (and then uses) all Mappings/Interceptors of the whole application. Thus we either end up creating and wiring all the spring-ws components by hand :( Or we start subclassing and customizing all Mappings/Interceptors adding code to check the Request-URL to decide if it should be invoked or not. |
Eberhard Wolff opened SPR-7170 and commented
In JavaConfig beans created by protected methods with
@Bean
annotation had visibility inside the@Configuration
class only but were not exported into the globalApplicationContext
and therefore cannot be referenced from there or other@Configuration
annotated classes:This is great to structure large configuration because beans can be hidden. Bring that feature back please.
Affects: 3.0 GA, 3.0.1, 3.0.2
Issue Links:
27 votes, 22 watchers
The text was updated successfully, but these errors were encountered: