Autowire Annotation in Spring without using component scan

Is it possible to @Autowired beans using the @Autowired annotation without using component scanning?

+4
source share
2 answers

Yes. <context-component-scan .. /> is responsible for detecting beans, annotated by @Component , @Controller , @Service , @Respository , etc.

To process annotations ( @Autowired , @Resource , etc.) you need <context:annotation-config /> . Thus, annotations are processed on beans, which are listed in applicationContext.xml .

As far as I know, <context-component-scan .. /> automatically activates <context:annotation-config /> .

This is true for both spring 2.5 and 3.0. (thanks scaffman)

+3
source

I never tried without component scanning enabled, however I can confirm that @Autowire annotations work in Spring 3.0.x even with beans that are defined via XML.

0
source

Source: https://habr.com/ru/post/1304330/


All Articles