Spring中bean注入报错的几种原因

报错类型:Error creating bean with name ‘indexJspController’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wg.blog.service.UpvoteService com.wg.blog.controller.IndexJspController.upvoteService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.wg.blog.service.UpvoteService] 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)}

可能原因:
1.spring-mvc配置文件错误,是否对所建的包进行了扫描
spring-mvc.xml
2.mapper.xml文件的命名空间namespace是否跟mapper文件的路径一致;
3.若确定没有以上错误,可以查看编译是否出错,在classes文件中查看自己的配置文件是否编译成功。若为编译出错在项目的pom.xml文件中加入以下代码即可
pom.xml

发布了15 篇原创文章 · 获赞 2 · 访问量 903
展开阅读全文

SpringBoot在IDE可以正常运行,但是部署到Tomcat里就会启动失败

08-03

我打算使用spring-boot + mybits plus构建一个RESTful服务器,在Eclipse里可以正常运行。但是一旦打包放到Tomcat里就会出现如下错误(NoSuchBeanDefinition),个人推测是某些配置文件没写完整或者有错误,导致的实例注入失败。 不过我检查了很多遍,尝试了很多办法,依然还是会有这个问题。 请各路大神帮帮忙!! 目录结构: java-xxx.xxx.xxx.xxx.dao |-xxx.xxx.xxx.xxx.entity(也就是javaBean类) |-xxx.xxx.xxx.xxx.service(业务逻辑接口) |-xxx.xxx.xxx.xxx.service.impl(业务逻辑实现类) |-xxx.xxx.xxx.xxx.controller resource-mapper . xxx . xxx.xml pom.xml版本信息: > mybatisplus.spring.boot.version-1.0.5 > mybatis-plus-2.3 > spring-boot-starter-parent-2.3 application.yml信息: mybatis-plus部分如下 > mapper-locations: classpath:mapper/**/*.xml > typeAliasesPackage: com.latou.power.modules.*.entity Java版本-1.8.0 Tomcat版本-8.5 Tomcat报错如下: > ConfigServletWebServerApplicationContext : > Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'custUserController': Unsatisfied dependency expressed through field 'custUserService'; > > nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'custUserService': Unsatisfied dependency expressed through field 'baseMapper'; > > nested exception is org.springframework.beans.factory.NoSuchBeanDefinition Exception: No qualifying bean of type 'com.latou.power.modules.cus.dao.CustUserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览