将Spring应用程序从XML迁移到注释

Dón*_*nal 4 java spring

我继承了一个Spring 3应用程序,该应用程序使用XML文件来定义和连接bean.我知道从Spring 2开始,这些大部分都可以用注释代替.我想春天:

  • 通过扫描某些包来检测bean,其中包含用于指示Spring bean的任何注释
  • 尝试在我用相关注释标记的bean中按名称和字段进行自动装配

为实现这一目标,我需要采取哪些步骤?

Car*_*osZ 5

手册包含您需要的所有信息: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配置中,然后使用@Component和在您的setter属性中注释您的bean 注释@Autowired