When you use @Autowired in a spring @Component, spring determines autowire candidates for every instantiation of the component, which is really not good when you use @Request/@Session scoped web stuff. Why doesn’t spring just make a bean definition within the ApplicationContext once and re-use that ? Is there any way to make it do so ?
When you use @Autowired in a spring @Component, spring determines autowire candidates for every
Share
AutowiredAnnotationBeanPostProcessoris aBeanPostProcessor, not aBeanFactoryPostProcessor, so it can’t edit Bean definitions, by design. Implementing that differently would break expected functionality:If no
OtherBeaninstance is available, none will be wired, but as soon as one becomes available (and I can easily programatically wire one), the nextMyBeaninstance (if scope is not singleton) will get the newOtherBean(which was not available before).I’m not saying this a use case I have encountered before, but it’s a valid use case and it would break if things worked the way you suggest that they should.