@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