为什么 spring boot 找不到我的豆子? [英] Why is spring boot not finding my beans?

查看:40
本文介绍了为什么 spring boot 找不到我的豆子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下错误:

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.

通常这是因为我忘记注释 Service 或界面,但我整个上午都在找课程,但找不到任何缺失的注释..

Usually this is because i forget to annotate either the Service or the interface, but i've been looking classes the whole morning and cant find any missing annotations..

此时的界面就是:

@Component
public interface ComposeCounterService {
CLASSX init(List<YYY> owners) throws JAXBException;
}

和实现服务如下,如果在这种情况下重要,则包含 init() 方法.

and implimenting service is as follows, and contains init() method if that matters in this case.

@Service
public class ComposeCounterImpl implements ComposeCounterService {
/*** loots of code
}

和 ApplicationConfig 文件位于服务包的上一级.在这篇文章中标记为xxx.

and ApplicationConfig file is located one level above the service package. marked xxx in this post.

它包含以下包扫描:

@SpringBootApplication
scanBasePackages = {"com.yyy.zzz.xxx")

我还尝试了一系列扫描,例如:

i also tried it with array of scans like:

scanBasePackages = {"com.yyy.zzz.xxx", "com.yyy.zzz.xxx.service.composeXML"})

并且在 .service 之后没有 composeXML这些都不起作用.

and without the composeXML after .service None of these works.

我很确定我在这里遗漏了一些东西,请发送帮助.

im pretty sure im missing something here, please send help.

注入方式:

private final ComposeCounterService composeCounterService;

public ControlService(ComposeCounterService composeCounterService) {
    this.composeCounterService = composeCounterService;
}

推荐答案

错误的导入是:

import org.jvnet.hk2.annotations.Service;

正确的是:

import org.springframework.stereotype.Service;

如果您只是让您的 IDE 建议导入并按 Enter 键而不阅读它添加的哪个,这就是结果.

If you just let your IDE suggest the import and press enter without reading which one it adds, this is the result.

这篇关于为什么 spring boot 找不到我的豆子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆