配置ssm项目报错:No qualifying bean of type ... found for dependency ...expected at least 1 bean which
程序员文章站
2024-03-11 20:27:55
...
配置ssm项目时,提示提示在service层注入出错,出错信息如下:大致的错误信息为:
cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘studentController’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘studentServiceImpl’: Unsatisfied dependency expressed through field ‘studentMapper’: No qualifying bean of type [com.csair.student.dao.StudentMapper] found for dependency [com.csair.student.dao.StudentMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
从中可以看出主要错误是注入时出错,这里注入的时mybatis generator自动生成的接口,网上的答案一般是mapping.xml中的namespace和实际的对应不上,可能字母拼写错误之类的,这个确实是常见的错误,以前我也犯过,但是我仔细核对发现并没错,后来找了很久,发现在web.xml里没有加载spring和mybatis整合的配置文件spring-mybatis.xml,加入后问题解决。
总结:这类问题的原因基本都是一些细节问题,以后遇到可以从这方面入手慢慢检查,拼写错误、配置文件未加载等等。
上一篇: JavaScript 判断对象是否为空
下一篇: idea后台打印表单提交的中文乱码问题