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

原文地址:https://www.cnblogs.com/shengulong/p/9942524.html