Spring Boot 1.2.1 没有找到依赖类型的合格 bean [英] Spring boot 1.2.1 No qualifying bean of type found for dependency

查看:52
本文介绍了Spring Boot 1.2.1 没有找到依赖类型的合格 bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已从 Spring Boot 版本 1.1.5 升级到 1.2.1,现在我得到 NoSuchBeanDefinitionException.

I have upgraded from spring boot version 1.1.5 to 1.2.1 and now I get NoSuchBeanDefinitionException.

我有简单的主类

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

后来我有回购

@Repository
public interface UserRepository extends MongoRepository<User, String>, UserRepositoryCustom {

   ...


}

自定义仓库

public interface UserRepositoryCustom {
    // custom methods
}

和 impl 类.

在将 spring boot 版本更新到 1.2.1 之前,一切都按预期工作.我已阅读 https://github.com/spring-projects/spring-boot/问题/2237 并尝试删除 @Repository 注释但没有成功.我错过了什么吗?感谢帮助

Before updating spring boot version to 1.2.1 everything was working as expected. I have read https://github.com/spring-projects/spring-boot/issues/2237 and tried to remove @Repository annotation but without success. Am I missing something? Thnx for help

编辑堆栈跟踪:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.respositories.UserRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)

推荐答案

有两种方法可以启用 JPA 存储库:

There are two ways to enable the JPA repositories:

要么使用 @EnableJpaRepositories 注释并指定参数(如基本存储库)或将属性 spring.data.jpa.repositories.enabled=true 添加到您的应用程序.properties 文件以激活 Spring Data JPA 的 Spring Boot 自动配置.

Either use the @EnableJpaRepositories annotation and specify the parameters (like base repositories) or add the property spring.data.jpa.repositories.enabled=true to your application.properties file to activate the Spring Boot auto configuration for Spring Data JPA.

@Repository 注释不适用于此用例,可以安全删除.

The @Repository annotation is not suitable for this usecase and can be removed safely.

如果你已经满足了所有条件,但是repositories仍然没有配置,那么你可以尝试添加Spring Boot Actuator模块,打开url http://yourserver.domain/autoconfig.这将为您提供所有自动配置及其状态以及原因(活动或非活动以及原因).检查 JpaRepositoriesAutoConfiguration 是否处于活动状态.

If you have fulfilled all conditions and the repositories are still not configured, then you can try to add the Spring Boot Actuator module, and open the url http://yourserver.domain/autoconfig. This will give you all auto configurations and their state with the reason (active or inactive and the reason for that). Check that for the JpaRepositoriesAutoConfiguration, if it is active or not.

这篇关于Spring Boot 1.2.1 没有找到依赖类型的合格 bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆