问题

  • 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注入问题解决的更多相关文章

  1. Linux下Tomcat项目启动报错

    Linux下Tomcat项目启动报错 org.springframework.beans.factory.CannotLoadBeanClassException: Error loading cla ...

  2. Eureka Server项目启动报错处理

    Eureka Server项目启动报错处理 Eureka是一个服务发现组件,提供服务注册.发现等注册中心功能,使用spring boot启动eureka应用时出现报错: 20:36:17.646 [r ...

  3. 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 创建 ...

  4. SSM项目启动报错:Failed to read candidate component class

    SSM项目启动报错:Failed to read candidate component class 换成3.1又没有问题,换成3.2又不行,查看编译环境用的是1.8,将1.8降为1.7,问题解决,服 ...

  5. eclipse 中导入 maven项目 启动报错

    导入Maven项目到Eclipse中时,出现问题如下: java.lang.ClassNotFoundException: org.springframework.web.context.Contex ...

  6. vue项目启动报错 spawn cmd ENOENT errno: -4058

    vue项目启动报错 spawn cmd ENOENT errno: -4058 运行vue项目(npm run dev)报错 提示 'npm' 不是内部或外部命令 cmd输入node -v 有版本号 ...

  7. 创建spring boot项目启动报错遇到的问题

    1.Spring boot,Mybatis 启动报错 Failed to auto-configure a DataSource *************************** APPLICA ...

  8. 【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 ...

  9. SpringBoot项目启动报错:java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

    .   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \( ( )\___ | '_ | '_| | ...

随机推荐

  1. Oracle decode和case的区别

    case在SQL中有两种写法,先建立一个表create table salgrade(grade int, sal int);insert into salgrade values(1,1000);i ...

  2. shell脚本下载网页图片

    和大家分享一个shell脚本写的图片抓取器.使用方法:img_downloader.sh.使用时在shell下输入:./img_downloader.sh www.baidu.com -d image ...

  3. my42_Mysql基于ROW格式的主从同步

    模拟主从update事务,从库跳过部分update事务后,再次开始同步的现象 主库 mysql> select * from dbamngdb.isNodeOK; +----+--------- ...

  4. 机器学习——可视化绘图matplotlib和seaborn

    安装matplotlib和seaborn https://blog.csdn.net/Jia_jinjin/article/details/80428598 seaborn pairplot:特征两两 ...

  5. 【C#】【MySQL】C#连接MySQL数据库(一)代码

    C#连接MySQL数据库 准备工作 1.环境安装 安装MySQL For Visual Studio<<点击进入官网下载 第一个要下载安装,第二个下载后将MySQL.data添加到Visu ...

  6. AT1980 [AGC001B] Mysterious Light 题解

    # 题意:高桥 くん 有一个边长为 N 的三枚镜子构成的正三角形 , 顶点为 a, b, c. 他有一个超级步枪 , 放在 AB 段的P点上,使得 AP=X . 并沿着平行于 BC 的方向发射一道光 ...

  7. 『学了就忘』Linux服务管理 — 76、RPM包安装的服务管理

    目录 1.独立服务的启动管理 2.独立服务的自启动管理 方式一: 方式二:(推荐) 方式三: 3.验证 1.独立服务的启动管理 (1)使用/etc/init.d/目录中的启动脚本启动服务(推荐) [r ...

  8. 攻击科普:DDos

    目录 一.DDoS 攻击究竟是什么? 二.DDoS 攻击多少G是什么意思? 二.DDoS攻击种类 ICMP Flood UDP Flood NTP Flood SYN Flood CC攻击 DNS Q ...

  9. python模块(三)

    hashilib模块 hashilib模块的主要作用是加密,可以将明文数据通过一系列算法转化为秘闻数据. 目的是为了数据的安全. 加密算法包括md系列,sha系列,base系列,hmac系列. 基本使 ...

  10. php-正则邮箱验证及详解

    当前的邮箱格式有哪些//1.第1种是QQ邮箱,它的后缀名是,@qq, .com.// 2.第2种是网易邮箱后缀名是,@163.com或者,@126.com// 3.第3种是雅虎邮箱,后缀名是,@yah ...