Is it possible to autowire beans using the @Autowired
annotation without using component scanning?
views:
348answers:
2Yes. <context-component-scan .. />
is responsible for discovering beans annotated with @Component
, @Controller
, @Service
, @Respository
, etc.
In order to have annotations processed (@Autowired
, @Resource
, etc) you need <context:annotation-config />
. Thus annotations are processed on beans that are listed in applicationContext.xml
.
As far as I know, <context-component-scan .. />
activates <context:annotation-config />
automatically.
This is true for both sprign 2.5 and 3.0. (thanks skaffman)
I've looked into this and I'm still not sure if I understand what you're saying. So, I don't want to use component-scanning to do this. And I'm wondering if there is a way to autowire components without using component-scanning and only with context:annotation-config. I googled for the annotation-config but didn't find any usages without component-scanning. Do you have any working examples of this?