

项目启动报错怎么办?看看你Spring自动注入用对了嘛?@Autowired XxxService注入问题解...
source link: https://segmentfault.com/a/1190000041213159
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

项目启动报错怎么办?看看你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容器注入规则
Recommend
-
46
前言 开心一刻 十年前,我:我交女票了,比我大两岁。妈:不行!赶紧分! 八年前,我:我交女票了,比我小两岁,外地的。妈:你就不能让我省点心? 五年前,我:我交女票了,市长的女儿。妈:别人还能看上你?分
-
21
1. 前言 @Resource 和 @Autowired 注解都可以在 Spring Framework 应用中进行声明式...
-
29
前言 各位小伙伴大家好,我是A哥。通过本专栏前两篇的学习,相信你对static关键字在Spring/Spring Boot里的应用有了全新的认识,能够解释工作中遇到的大多数问题/疑问了。本文继续来聊聊static关键字更为常见的一种case:使用 @Autowired
-
30
01 问题背景 最近,在使用idea开发时业务系统时,发现idea上使用了@Autowired,发现竟然被警告了!提示:Field injection is no...
-
9
面试中碰到面试官问:”Spring 注解是如果工作的?“,当前我一惊,完了这不触及到我的知识误区了吗?,还好我机智,灵机一动回了句:Spring 注解的工作流程倒还没有看到,但是我知道 @Autowired 注解的工作流程,后面不用说...
-
15
QQA: 如何启用 @Autowired@Autowired 是 Spring 提供的一个注解,作用是自动装配 Bean 所需要的依赖。但 @Autowired 只是告诉 Spring 当前的 Bean 依赖了其它的 Bean,那么如何让 Spring 真正“启用”自动装配的功...
-
15
如何实现一个简易版的 Spring - 如何实现 @Autowired 注解 发表于...
-
14
idea启动springboot项目报错 Command line is too long 解决方法 Wiken 2021-05-18 错误:Error ru...
-
29
添加knife4j配置后项目启动报错 - OSCHINA - 中文开源技术交流社区 开源问答...
-
1
【踩坑】JavaWeb项目启动时报错 2023-02-23 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK