I am using Java-based Spring configuration in my project, specifying bean construction in @Bean-annotated methods in @Configuration. Recently, Recently, I've started to think that maybe it would've been better to use @Autowired to remove all non-important beans from @Configuration, leaving only small "root" set of them (key services and technical beans like those of Spring MVC).
Unfortunately, it seems that Spring can notice implementations for @Autowired dependencies only if they are inside component-scanned package which I cannot do without resorting to some XML.
Is there any way to use @Autowired with Java-based configuration without explicitly specifying each bean?
@Autowiredworks just fine inside normal@Bean-style configs, component-scanning is not required (or even desirable). Please give an example of what you have. - skaffman@Bean MyService servicethat has an@Autowired IDao dao. There is aninterface IDaoandclass DaoImpl implements IDaoand there are no other implementations forIDao. As I understand, it is necessary to either declare a@Bean IDao dao() { return new DaoImpl }or use component scanning. Otherwise, I'm getting theNo matching bean of type IDao found for dependencyexception. - Fixpoint@ComponentScan. No need for XML. - Nick