1、在 XML 注入之前进行注解注入,因此后者可以被前者重写。
2、在默认情况下注解在 Spring 容器中不打开,需要配置启动。
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:annotation-config/> </beans>
3、注解的位置有属性、方法和构造函数。
从 Spring 2.5 开始就可以使用注解来配置依赖注入,而不是采用 XML 来描述一个 bean。
原文:http://www.cnblogs.com/wangdapeng/p/5053483.html