简体   繁体   English

Spring-Boot创建名称不完整的bean将导致“ NoSuchBeanDefinitionException,找不到依赖类型为[]的合格bean”

[英]Spring-Boot create bean with out name will cause “NoSuchBeanDefinitionException, No qualifying bean of type[]found for dependency ”

I Create the bean by configuration with out name 我通过配置用名字创建bean

@Configuration
@ConfigurationProperties(prefix = "mysql")
public class DbConfiguration extends BaseDbConfiguration {

  @Bean//(name = "fix")
  @Override
  public DbClient createClient() {
      return super.createClient();
  }

}

usage: 用法:

@Autowired
private DbClient dbClient;

when I running application it can't start up 当我运行应用程序时无法启动

And throw NoSuchBeanDefinitionException: 并抛出NoSuchBeanDefinitionException:

No qualifying bean of type [DbClient] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. 找不到依赖项的类型为[DbClient]的合格Bean:至少应有1个符合此依赖项的自动装配候选条件的bean。 Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}

But I fix it by add name, why?? 但是我通过添加名称来解决它,为什么?

@Bean(name = "fix")

I also add a test such like this: 我还添加了这样的测试:

public class TestCreate {

    @NotNull
    private int test;

    public Test createTest() {
        return new Test(this.test);
    }

}

it configuration like this: 它的配置是这样的:

@Configuration
@ConfigurationProperties(prefix = "test")
public class TestConfiguration extends TestCreate {

    @Override
    @Bean
    public Test createTest() {
        return super.createTest();
    }

}

And autowired like this: 并像这样自动布线:

@Autowired
private Test test;

However, this test may work well 但是,此测试可能效果很好

It also create Bean without name and Autowired with out Qualifier 它还会创建没有名称的Bean,并在没有限定符的情况下自动装配

Please Tell me why....thanks 请告诉我为什么...。谢谢

Sorry. 抱歉。

I have found the results: 我发现了结果:

Overriding bean definition for bean 'createClient': replacing ... 覆盖bean'createClient'的bean定义:替换...

So Spring-Boot will create Bean by FunctionName rather than returning ObjectName. 因此,Spring-Boot将通过FunctionName创建Bean,而不是返回ObjectName。

暂无
暂无

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

相关问题 NoSuchBeanDefinitionException:未找到依赖关系类型为JpaVendorAdapter的合格Bean - NoSuchBeanDefinitionException: No qualifying bean of type JpaVendorAdapter found for dependency NoSuchBeanDefinitionException:找不到类型合格的bean - NoSuchBeanDefinitionException: No qualifying bean of type found 春季启动OAuth2实现:NoSuchBeanDefinitionException:没有类型为AuthenticationManager的合格Bean - Spring-boot OAuth2 implementation: NoSuchBeanDefinitionException: No qualifying bean of type AuthenticationManager 在Spring Boot单表中找不到依赖项类型的合格Bean - No qualifying bean of type found for dependency in Spring Boot single table NoSuchBeanDefinitionException: 找不到类型为 [project.dao.ServiceUserDao] 的合格 bean 依赖项 - NoSuchBeanDefinitionException: No qualifying bean of type [project.dao.ServiceUserDao] found for dependency NoSuchBeanDefinitionException:找不到依赖项类型为[org.hibernate.SessionFactory]的合格bean - NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency 升级到Spring Boot 1.5.4会导致NoSuchBeanDefinitionException没有类型PlatformTransactionManager的合格bean - Upgrade to Spring Boot 1.5.4 causes NoSuchBeanDefinitionException No qualifying bean of type PlatformTransactionManager Spring Data Redis NoSuchBeanDefinitionException:没有类型的限定bean - Spring Data Redis NoSuchBeanDefinitionException: No qualifying bean of type NoSuchBeanDefinitionException: 没有为依赖找到 [Repository] ​​类型的合格 bean:预计至少有 1 个符合自动装配条件的 bean - NoSuchBeanDefinitionException: No qualifying bean of type [Repository] found for dependency: expected at least 1 bean which qualifies as autowire 找不到依赖类型的合格Bean - No qualifying bean of type found for dependency
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM