本文主要是介绍解决SSM项目中 ServiceTest类方法报No qualifying bean of type ‘com.dao.XXXMapper‘ available错问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
具体错误为:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userServiceImpl’: Unsatisfied dependency expressed through field ‘userMapper’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.dao.UserMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
这个错误的意思是:Spring找不到XXXMapper文件。
有以下几个原因
①配置的扫描包位置错误
Mapper扫描包配置,value属性指的是扫描的位置,应该是mapper文件放置的位置
service扫描的配置,value应该是service文件放置的位置
②@ContextConfiguration注解中的配置文件写错(我的错误)
应改为classpath:ApplicationContext.xml,同时在ApplicationContext.xml中应当引入spring-dao.xml,和spring-service.xml两个文件,从而让spring可以将它们整合在一起。
这篇关于解决SSM项目中 ServiceTest类方法报No qualifying bean of type ‘com.dao.XXXMapper‘ available错问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!