具体错误为:
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