Spring Unsatisfied dependency expressed through constructor argument with index 0 of type

后端 未结 4 1976
既然无缘
既然无缘 2021-02-07 22:24

The full message is

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: 
    Error creating bean with name \'userRepositoryUserDetailsSe         


        
相关标签:
4条回答
  • 2021-02-07 23:13

    Annotatate your class implementing UserRepository with spring @Component annotation

    @Component
    public MyUserRepository implements UserRepository
    {
        User findByEmail(String email){
                return new User();
        }
    }
    
    0 讨论(0)
  • 2021-02-07 23:17

    [org.cru.cloud.management.data.UserRepository]: : No qualifying bean of type

    Can not find UserRepository bean. Maybe you forgot to put annotation to UserRepository.

    @Component
    public MyClass implements UserRepository{}
    

    if you autowire userRepository then you MyClass will be injected.

    Also :

    public MyClass implements UserRepository{}
    public YourClass implements UserRepository{}
    
    @Autowired
    public blabla(@Qualifier("myClass") UserRepository userRepo)
    
    @Autowired
    public blabla(@Qualifier("yourClass") UserRepository userRepo)
    

    I guess this will help.

    0 讨论(0)
  • 2021-02-07 23:21

    Do you have the @EnableJpaRepositories annotation somewhere in your config classes and is the scan set up correctly? By default the package in which the annotated class or interface exists becomes the base package for repository scan. You can control that by setting a value to the basePackages (or even better - basePackageClasses) property.

    You could use Spring Tools Suite to check, what beans are declared in your context (Repositories should be visible under Spring Elements > Beans > Spring Data Repositories).

    0 讨论(0)
  • 2021-02-07 23:29

    It seems you are using @EnableJpaRepositories to configure the database repository. It has two option load beans, the following one method you can use.

    @EnableJpaRepositories(basePackages={"com.test.repo"})
    

    or

    @EnableJpaRepositories(basePackageClasses=TestRepo.class)
    
    0 讨论(0)
提交回复
热议问题