首页 > 解决方案 > NoSuchBeanDefinition 由于通过构造函数参数 0 表示的不满足依赖关系

问题描述

我使用标记为@Provider 的库 X 的类(JAX-RS 的注释)。

我想扩展 X 的功能,所以我扩展了这个类:

@Provider
public class WrappedX extends ContainerRequestFilter,
ContainerResponseFilter {
     private final X objectX;
     public WrappedX (X objectX) { this.objectX = objectX; } }
     @Override
     <Some function1>
     @Override
     <Some function2>
}

在另一个文件中,我创建 WrappedX Spring Configuration 类:

@Configuration
public class WrappedXConfig {
  @Bean
  public WrappedX getWrappedXFilter(){
      X objectX = new XBuilder().build();
      return new WrappedX(objectX);
  }

}

当我运行它时,我得到了错误:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: 
    Error creating bean with name 'getWrappedXFilter' defined in file 
    [<path>/WrappedX.class]: 

 Unsatisfied dependency expressed through constructor argument with index 0 of type  [org.company.package1.X]: : No qualifying bean of 
 type [org.company.package1.X] found for dependency: 
     expected at least 1 bean which qualifies 
     as autowire candidate for this dependency. 
  Dependency annotations: {};  nested exception is 
 org.springframework.beans.factory.NoSuchBeanDefinitionException: 
    No qualifying bean of type [org.company.package1.X] found 
    for dependency: expected at least 1 bean 
    which qualifies as autowire candidate for this dependency. 
  Dependency annotations: {}

我看到另一段代码与我所做的完全一样。但他们运行他们的代码就好了。有人可以解释这里发生了什么吗?

标签: javaspringdependency-injectionjax-rs

解决方案


推荐阅读