-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Support disabling @Autowired on a per-@Bean basis [SPR-8396] #13043
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
Chris Beams commented Hi Stepan, It's probably not terribly common to declare For a number of reasons, it probably won't take the shape that you've described above, but we could consider something like the following:
The We'll review this for 3.1 and see if makes the cut. |
Chris Beams commented It will also be important to distinguish any such new attribute from the existing Bean#autowire attribute, which controls 'automagic' by-name/by-type autowiring, which is wholly different than annotation-config style autowiring. The former is already off (Autowire.NO) by default because it's generally discouraged; the latter is enabled by default, and implementing this request would provide the user with a way to disable it on a per- |
Stepan Koltsov commented Chris, I still want other bean properties to be autowired (as in XML conf). |
Chris Beams commented Hi Stepan, Could you clarify a bit further? Are you saying that you want by-name/by-type autowiring to occur for this bean (that's what "as in XML conf" sounds like to me); or are you saying that you still want |
Stepan Koltsov commented Chris, Yes, I still want both Sorry for late answer. |
Chris Beams commented Hi Stepan, After some consideration, resolving this as "Won't Fix" for now. There's seems to be no elegant way to achieve the kind of per-property disabling that you're looking for, and I'm afraid the nested annotation approach suggested with If this emerges as a more common need, we can revisit it. |
Juan commented Hi, Can we have this bit implemented? I have a "Generic abstract DAO" class which has this:
Implementations only specify the type of the entity being managed and that's it. It works great when there is only one DB and one session factory in the context (most of the time). But I have an app that connects to three different DBs, and I am not being able to use my generic DAO there. I can use I believe In the mean time, I was able to work around the problem by returning a FactoryBean<...> from the Thanks, |
David Česal commented I would like to set |
Yanming Zhou commented I have encounter the same problem like Stepan Koltsov , currently workaround is mixing xml configuration. I'm vote for introduce a new @Bean
@BeanPropertySource(properties = { "bla=from @Bean" })
public TheBean theBean() {
return new TheBean();
}
|
We have no intention to introduce a dedicated mechanism for such disabling. Our recommendation is rather to structure application components accordingly between constructor arguments and bean properties: Constructor arguments are effectively replaced in the Alternatively, you may entirely go for constructor-based injection and declare the required autowired arguments as parameters on your |
Uh oh!
There was an error while loading. Please reload this page.
Stepan Koltsov opened SPR-8396 and commented
Obviously outputs
and property specified in
@Bean
method has lower priority.Requesting a
@Bean
(properties=...) attribute, so theBean() declaration could be written as:In this case Spring would call setBla only once with "from
@Bean
" parameter value.Assume HttpServer library class with
@Autowired
threadPool property. I cannot declare two HttpServer instances that use different thread pools in the same application (without disabling autowire, switching to xmlconf etc).Affects: 3.1 M1
Attachments:
Issue Links:
@Bean
1 votes, 4 watchers
The text was updated successfully, but these errors were encountered: