在不使用组件扫描的情况下在Spring中自动装配注释

udi*_*dit 6 spring dependency-injection ioc-container autowired

是否可以在@Autowired不使用组件扫描的情况下使用注释自动装配bean ?

Boz*_*zho 4

是的。<context-component-scan .. />负责发现带有@Component@Controller@Service@Respository等注释的 bean。

为了处理注释(@Autowired@Resource等),您需要<context:annotation-config />. 因此,注释是在 中列出的 bean 上进行处理的applicationContext.xml

据我所知,会自动<context-component-scan .. />激活<context:annotation-config />

对于 spring 2.5 和 3.0 都是如此。(感谢斯卡夫曼)