Spring 通过一个 BeanPostProcessor 对 @Autowired 进行解析,所以要让 @Autowired 起作用必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。 <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> 当 Spring 容器启动时,AutowiredAnnotationBeanPostProcessor 将扫描容器中的所有 Bean,如果发现 Bean 中存在 @Autowired 注释,就会寻找和其匹配的 Bean 注入。Bean 中使用了 @Autowired 注释的变量,不再需要 setter 方法。