我继承了一个 Spring 3 应用程序,它使用 XML 文件来定义 Bean 并将其连接在一起。我知道从 Spring 2 开始,这些大部分都可以用注释替换。我希望 Spring 能够:
- 通过扫描某些包中的类来检测 bean,无论使用什么注释来指示 Spring bean
- 尝试在我用相关注释标记的 bean 中按名称和字段进行自动装配
我需要采取哪些步骤才能实现这一目标?
该手册包含您需要的所有信息:http://static.springsource.org/spring/docs/3.1.0.M1/spring-framework-reference/html/beans.html#beans-annotation-config http://static.springsource.org/spring/docs/3.1.0.M1/spring-framework-reference/html/beans.html#beans-annotation-config
TL;DR 版本是您需要添加<context:annotation-config/>
到你的 spring 配置,然后用注释你的 bean@Component
并在你的属性设置器中注释@Autowired
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)