简体   繁体   English

NoSuchBeanDefinitionException: 没有“XInterceptor”类型的合格 bean

[英]NoSuchBeanDefinitionException: No qualifying bean of type "XInterceptor"

I'm getting lost in making sure everything is annotated properly apparently.我迷失在确保所有内容都明显正确注释的过程中。 When i run a service that uses this new code, I get the error below.当我运行使用此新代码的服务时,出现以下错误。 Isn't the interceptor a bean already with the @Component and then everything it needs to be a bean within is a 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

I have a someDecorator class that uses the intercepter that I have made changes to:我有一个someDecorator类,它使用我已更改的拦截器:

@Component 
@RequiredArgsConstructor 
public class someDecorator { 

    private final XInterceptor xInterceptor; 
    ...
    private void useTheInterceptor(...) {
      ...
      aList.add(xInterceptor) // and use it for later
    }
}

Now the xInterceptor , which uses a another class YProvider现在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 
    }

The YProvider is where it gets interesting, it has a two values. YProvider是它变得有趣的地方,它有两个值。 ZProperties which is a config class and a consumer map. 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 just captures a map from an application.yml file: ZProperties只是从application.yml文件中捕获地图:

@Configuration
@ConfigurationProperties(prefix = "some-config")
@EnableConfigurationProperties
@Getter
@Setter
public class ZProperties {
    private Map<String, String> exampleMap;
}

Now to populate the consumers map in YProvider and to set up YProvider , I have another config ConsumerConfig现在要在YProvider填充consumers映射并设置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;
    }
}

It could be because you didn't provide the XInterceptor as a Bean in you configuration file.这可能是因为您没有在配置文件中将 XInterceptor 作为 Bean 提供。

Try adding this to your ConsumerConfig class.尝试将其添加到您的 ConsumerConfig 类中。

    @Bean
    public XInterceptor getXInterceptor(){
     return new XInterceptor();
    }

由于我将这些文件放在不同的包中,因此我必须添加@ComponentScan以及 Intercepter+Provider 所在位置的包名称和配置文件所在位置的包。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NoSuchBeanDefinitionException: 没有“int”类型的合格 bean - NoSuchBeanDefinitionException: No qualifying bean of type 'int' NoSuchBeanDefinitionException:没有类型合格的bean(存储库) - NoSuchBeanDefinitionException: No qualifying bean of type (repository) NoSuchBeanDefinitionException:找不到类型合格的bean - NoSuchBeanDefinitionException: No qualifying bean of type found NoSuchBeanDefinitionException:没有符合条件的 bean 类型(JpaRepository 和 Java Config) - NoSuchBeanDefinitionException: No qualifying bean of type (JpaRepository and Java Config) 如何解决“ NoSuchBeanDefinitionException:没有类型的合格bean”错误? - How to cure 'NoSuchBeanDefinitionException: No qualifying bean of type' error? Spring Data Redis NoSuchBeanDefinitionException:没有类型的限定bean - Spring Data Redis NoSuchBeanDefinitionException: No qualifying bean of type NoSuchBeanDefinitionException:没有内部类的合格 bean - NoSuchBeanDefinitionException: No qualifying bean of type for inner class NoSuchBeanDefinitionException:未找到依赖关系类型为JpaVendorAdapter的合格Bean - NoSuchBeanDefinitionException: No qualifying bean of type JpaVendorAdapter found for dependency NoSuchBeanDefinitionException:没有要自动装配的JobLauncher类型的合格Bean - NoSuchBeanDefinitionException: No qualifying bean of type JobLauncher to autowire NoSuchBeanDefinitionException: 没有合格的 bean - NoSuchBeanDefinitionException: No qualifying bean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM