Spring与SpringMVC 的整合使用报错不能够自动装配

来源:互联网 发布:淘宝免单微信群2017 编辑:程序博客网 时间:2024/05/17 23:59

问题:Spring与SpringMVC 的整合使用 时,出现以下问题
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
原因:我在两个配置文件xml中的注解扫描器扫描的包路径冲突了
<!-- 扫描器 -->
<context:component-scan base-package="pers.h.finalproject.controller"></context:component-scan>

解决方法:只要将springmvc-servlet.xml 和 applicationContext.xml中的两个扫描器扫描的包改为不相同的路径。

原创粉丝点击