Spring 如何开启基于注解的自动装配?

要使用 ​​@Autowired​​​,需要注册 ​​AutowiredAnnotationBeanPostProcessor​​,可以有以下两种方式来实现:

引入配置文件中的​​<bean>​​​下引入 ​​<context:annotation-config>​​

 

<beans>
    <context:annotation-config />
</beans>

 

在bean配置文件中直接引入​​AutowiredAnnotationBeanPostProcessor​​

 

<beans>
    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
</beans>

 

posted @   BookerABC  阅读(101)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示