Hi,
I've been playing a lot with porting all of my apps to Spring 3 with almost fully Java-centric configuration. I actually ended up mixing in some XML for property placeholders and autoscanning but most of my code is autowired and then manually put together using several @Configurations which import each other.
I've been running into a recurring issue. If I have an @Autowired object (objA) within a @Configuration then I cannot set anything that may be @Required but not @Autowired on the object. Example:
Now I have nowhere to setSomeNotAutowireAbleProperty on my instance of a and thus I cannot inject it without using @Bean. However, if I use @Bean then I have to provide all of my dependency injections explicitly within the function.Code:class ObjA() { @Autowired public ObjA(/*several requirements I never want to think about*/) { //... } @Required public void setSomeNotAutowireAbleProperty(DepA dep) { //... } } @Configuration class ConfigA() { @Autowired ObjA a; }
Is there a way to partially @Autowire (particularly object construction) an object and partially wire an object with setters from a @Configuration? If not could perhaps @PostConstruct of a configuration run before @Required validations on other beans? Or am I trying to do something a bit out there?
Thanks.


Reply With Quote