1. 程式人生 > >Spring @Autowired 註解不生效

Spring @Autowired 註解不生效

@Autowired
預設不生效。為了生效,需要在xml配置:<context:annotation-config>



註解一<context:component-scan base-package=" "> 開啟包掃描

註解二<context:annotation-config>開啟注入註解掃描

一般情況下,兩個註解不一起使用.

當"註解一",掃描含有註解@Component/@Service等的類時,注入註解自動生效就不需要配置註解二了

當要掃描的類上沒有含有@Component/@Service等註解時,注入註解沒有生效,那麼只需要添加註解二即可
---------------------

原文:https://blog.csdn.net/Static_725/article/details/79582533