java - 为什么弹簧靴找不到我的豆子?
问题描述
我有以下错误:
Parameter 0 of constructor in com.yyy.zzz.xxx.service.ControlService required a bean of type 'com.yyy.zzz.xxx.service.composeXML.ComposeCounterService' that could not be found.
通常这是因为我忘记对服务或界面进行注释,但我整个上午都在寻找课程并且找不到任何丢失的注释..
此时的界面只是:
@Component
public interface ComposeCounterService {
CLASSX init(List<YYY> owners) throws JAXBException;
}
和实施服务如下,如果在这种情况下很重要,则包含 init() 方法。
@Service
public class ComposeCounterImpl implements ComposeCounterService {
/*** loots of code
}
ApplicationConfig 文件位于服务包之上一层。在这篇文章中标记为 xxx。
它包含以下包扫描:
@SpringBootApplication
scanBasePackages = {"com.yyy.zzz.xxx")
我还尝试了一系列扫描,例如:
scanBasePackages = {"com.yyy.zzz.xxx", "com.yyy.zzz.xxx.service.composeXML"})
并且没有 .service 之后的 composeXML 这些都不起作用。
我很确定我在这里遗漏了一些东西,请发送帮助。
编辑:注入风格:
private final ComposeCounterService composeCounterService;
public ControlService(ComposeCounterService composeCounterService) {
this.composeCounterService = composeCounterService;
}
解决方案
错误的导入是:
import org.jvnet.hk2.annotations.Service;
正确的是:
import org.springframework.stereotype.Service;
如果您只是让您的 IDE 建议导入并按 Enter 键而不阅读它添加了哪个,这就是结果。
推荐阅读
- python-3.x - 防止运行脚本或禁用按钮 - tkinter
- apache-kafka - 如何在 KSQL 中选择/分配分区
- css - 如何设置基于flex或grid的动态网格
- excel - Excel Solver 排除价格为零的地方
- emacs - 有没有办法根据子标题 todo-keywords 计算 org-mode 标题属性?
- windows - 从 powershell 输出中删除文本
- node.js - 使用 NodeJS Bull Queue 独立处理器
- javascript - 用文本替换损坏的图像
- javascript - 如何在 Blazor 客户端中正确获取 facebook 登录令牌?
- html - 如何根据时间戳和电子表格上的文本在图表上添加文本标签