@Autowired失败@Resource成功
我在spring文件中配置了 <bean id="paramParse" class="xxxx.ParamParse"/>
在java代码里面使用 @Autowired private ParamParse paramParse; 就是 null ;
换成了 @Resource private ParamParse paramParse; 就注入成功了! 完全不知道错在哪里。。。
在我项目的 web.xml 里面,加载了spring配置,也有ContextLoaderListener监听器:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/config/spring*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
在spring-mvc配置里面,也加载了注解配置 <mvc:annotation-driven />
还有 <context:component-scan base-package=...>