[英]NoSuchBeanDefinitionException: No qualifying bean of type JpaVendorAdapter found for dependency
[英]Spring-Boot create bean with out name will cause “NoSuchBeanDefinitionException, No qualifying bean of type[]found for dependency ”
我通过配置用名字创建bean
@Configuration
@ConfigurationProperties(prefix = "mysql")
public class DbConfiguration extends BaseDbConfiguration {
@Bean//(name = "fix")
@Override
public DbClient createClient() {
return super.createClient();
}
}
用法:
@Autowired
private DbClient dbClient;
当我运行应用程序时无法启动
并抛出NoSuchBeanDefinitionException:
找不到依赖项的类型为[DbClient]的合格Bean:至少应有1个符合此依赖项的自动装配候选条件的bean。 依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
但是我通过添加名称来解决它,为什么?
@Bean(name = "fix")
我还添加了这样的测试:
public class TestCreate {
@NotNull
private int test;
public Test createTest() {
return new Test(this.test);
}
}
它的配置是这样的:
@Configuration
@ConfigurationProperties(prefix = "test")
public class TestConfiguration extends TestCreate {
@Override
@Bean
public Test createTest() {
return super.createTest();
}
}
并像这样自动布线:
@Autowired
private Test test;
但是,此测试可能效果很好
它还会创建没有名称的Bean,并在没有限定符的情况下自动装配
请告诉我为什么...。谢谢
抱歉。
我发现了结果:
覆盖bean'createClient'的bean定义:替换...
因此,Spring-Boot将通过FunctionName创建Bean,而不是返回ObjectName。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.