java - NoSuchBeanDefinitionException:没有“XInterceptor”类型的合格 bean
问题描述
我迷失了确保所有内容都明显正确注释。当我运行使用此新代码的服务时,我收到以下错误。拦截器不是已经带有@Component的bean,然后它需要成为一个bean的所有东西都是一个bean?
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.demo...XInterceptor' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1654)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1213)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)
... 88 common frames omitted
Process finished with exit code 1
我有一个someDecorator
使用我已更改的拦截器的类:
@Component
@RequiredArgsConstructor
public class someDecorator {
private final XInterceptor xInterceptor;
...
private void useTheInterceptor(...) {
...
aList.add(xInterceptor) // and use it for later
}
}
现在xInterceptor
, 它使用另一个类YProvider
@Component
@RequiredArgsConstructor
public class xInterceptor {
private final YProvider yProvider;
public ClientHttpResponse intercept(String str, ...) throws IOException {
Consumer<String> loggingConsumer = yProvider.getLoggingLevel(str);
// ... use the consumer
}
这YProvider
是它变得有趣的地方,它有两个值。ZProperties
这是一个配置类和一个消费者地图。
@RequiredArgsConstructor
public class YProvider {
private final ZProperties zProperties;
private final Map<String, Consumer<String>> consumers;
public Consumer<String> getLoggingLevel(String str) {
// gets a single consumer from zProperties.getExampleMap ...
}
ZProperties
只是从application.yml
文件中捕获地图:
@Configuration
@ConfigurationProperties(prefix = "some-config")
@EnableConfigurationProperties
@Getter
@Setter
public class ZProperties {
private Map<String, String> exampleMap;
}
现在要填充consumers
地图YProvider
并进行设置YProvider
,我有另一个配置ConsumerConfig
@Configuration
public class ConsumerConfig {
@Bean
public YProvider yProvider(ZProperties zProperties) {
return new YProvider(zProperties, exmapleMapToConsumerConfiguration());
}
public Map<String, Consumer<String>> exmapleMapToConsumerConfiguration() {
Map<String, Consumer<String>> exmapleMapToConsumerMap = new ConcurrentHashMap<>();
// add stuff to map
return exmapleMapToConsumerMap;
}
}
解决方案
由于我将这些文件放在不同的包中,因此我必须添加@ComponentScan
Intercepter+Provider 所在的包名和配置文件所在的包。
推荐阅读
- jupyter-notebook - cocalc:如何添加 julia 内核?
- arrays - 通过firebase firestore上的数组内的对象值查询
- html - 填写一个框固定宽度
- css - 如何从图像元素中分离背景不透明度转换
- mysql - 我有三个查询链接以将一个表从 oracle 提取到 SAS,但第三个查询没有输出任何输出,我没有发现错误
- swift - 出现致命错误,提示“JVP 不存在。微分优先微分 API 是实验性的,不应使用。”
- c# - EF Core 中的单边一对一关系和级联删除问题
- github - 如何在 GitHub 操作中安装旧版本的 Direct X Api
- python-3.x - Pandas Dataframe 使用 Merge 过滤结果。编码解码问题
- python - 如何在用户输入的字符串中添加数字