views:

348

answers:

2

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

+2  A: 

Yes. <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)

Bozho
@Bozho Good (+1) Take a look at this question: http://stackoverflow.com/questions/2458769/how-to-create-commandlink-programmatically
Arthur Ronald F D Garcia
(+1) Yes, this is still the case in 3.0
skaffman
A: 

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?

udit