项目启动报错怎么办?看看你Spring自动注入用对了嘛?@Autowired XxxService注入问题解决
问题
- 在Controller层使用 @Autowired注入Service时,提示Bean中没有Service
- 在Service接口中使用 @Component注入后,启动项目问题提示:
The web application [ROOT] appears to have started a thread named [DubboClientReconnectTimer-thread-2] but has failed to stop it.
This is very likely to create a memory leak
原因
- 提示Bean中没有Service:
- 因为没有将Service注入到Spring容器中,可以通过 @Component或者 @Service注解注入
- 在Service中使用注解注入到容器后,启动项目会报错:
- 因为在Service接口注入,同时注入了两个Bean
- 在Service接口注入,会将实现Service接口的子类也注入到容器中,所以会导致Dubbo重复性线程错误
解决办法
- 在Service的实现类ServiceImpl上,使用 @Component或者 @Service注解将Service注入到Spring容器中
- 如果是使用Dubbo的SpringBoot项目,可以在Service实现类使用如下注解
@com.alibaba.dubbo.config.annotation.Service
@org.springframework.stereotype.Service
- 注意: 要将Service实现类注入到容器,而不是Service接口
总结
- Spring容器注入规则
项目启动报错怎么办?看看你Spring自动注入用对了嘛?@Autowired XxxService注入问题解决的更多相关文章
- Linux下Tomcat项目启动报错
Linux下Tomcat项目启动报错 org.springframework.beans.factory.CannotLoadBeanClassException: Error loading cla ...
- Eureka Server项目启动报错处理
Eureka Server项目启动报错处理 Eureka是一个服务发现组件,提供服务注册.发现等注册中心功能,使用spring boot启动eureka应用时出现报错: 20:36:17.646 [r ...
- springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde
springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde 创建 ...
- SSM项目启动报错:Failed to read candidate component class
SSM项目启动报错:Failed to read candidate component class 换成3.1又没有问题,换成3.2又不行,查看编译环境用的是1.8,将1.8降为1.7,问题解决,服 ...
- eclipse 中导入 maven项目 启动报错
导入Maven项目到Eclipse中时,出现问题如下: java.lang.ClassNotFoundException: org.springframework.web.context.Contex ...
- vue项目启动报错 spawn cmd ENOENT errno: -4058
vue项目启动报错 spawn cmd ENOENT errno: -4058 运行vue项目(npm run dev)报错 提示 'npm' 不是内部或外部命令 cmd输入node -v 有版本号 ...
- 创建spring boot项目启动报错遇到的问题
1.Spring boot,Mybatis 启动报错 Failed to auto-configure a DataSource *************************** APPLICA ...
- 【spring cloud】【spring boot】项目启动报错:Cannot determine embedded database driver class for database type NONE
解决参考文章:https://blog.csdn.net/hengyunabc/article/details/78762097 spring boot启动报错如下: Error starting A ...
- SpringBoot项目启动报错:java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \( ( )\___ | '_ | '_| | ...
随机推荐
- 顺序栈(C++)
栈的定义为只允许在表的末端进行插入和删除的线性表.简而言之就是先进后出的线性表. 插入和删除的一端被称呼为栈顶(top),而不允许插入删除的一端被称为栈底(bottom).无元素时的栈即为空栈. 使用 ...
- Lottie 使用
原文:https://mp.weixin.qq.com/s?__biz=MzIxNjc0ODExMA==&mid=2247485033&idx=1&sn=54dd477b4c4 ...
- 复制virtualbox虚拟硬盘
D:\VirtualBox\VBoxManage.exe clonevdi F:\virtualbox\rac1\rac1.vdi F:\virtualbox\rac2\rac2.vdi 虚拟机软件安 ...
- ajaxSubmit返回JSON格式
开发时遇到根据不同情况返回错误提示信息的需求,用到了ajax中返回json格式数据的. 前台请求代码: <script type="text/javascript"> ...
- ORACEL 创建DIRECTORY
oracle要直接对文件进行读写必须先创建一个DIRECTORY. 语法如下: CREATE DIRECTORY UTL_FILE_DIR AS '/home/oracle/oradir'; 可以通过 ...
- vue-cli 如何配置assetsPublicPath; vue.config.js如何更改assetsPublicPath配置;
问题: vue项目完成打包上线的时候遇到静态资源找不到的问题,网上很多解决办法都是基于vue-cli 2.x 来解决的,但从vue-cli 3.0以后,便舍弃了配置文件夹(便没有了config这个文件 ...
- 【编程思想】【设计模式】【行为模式Behavioral】Specification
Python版 https://github.com/faif/python-patterns/blob/master/behavioral/specification.py #!/usr/bin/e ...
- ubuntu qq/微信
Ubuntu qq&微信安装/启动脚本. Docker 本脚本依赖Docker,需要提前安装好Docker环境.参考https://yeasy.gitbooks.io/docker_pract ...
- html上传图片的预览功能实现
表单代码(仅取上传文件部分): <input class="selectImg" style="position:absolute;opacity: 0;width ...
- 前端浅谈-协议相关(http/https)
当DNS工作完之后得到了一个网址 https//192.168.1.255/index.html 这个并不符合标准的请求路径.接下来就是https的功能了.讲https前先讲讲它的前身http协议 H ...