Reputation: 739
I have upgraded from spring boot version 1.1.5 to 1.2.1 and now I get NoSuchBeanDefinitionException
.
I have simple main class
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
and later I have repo
@Repository
public interface UserRepository extends MongoRepository<User, String>, UserRepositoryCustom {
...
}
custom repo
public interface UserRepositoryCustom {
// custom methods
}
and impl class.
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
EDIT stacktrace:
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)
Upvotes: 0
Views: 10209
Reputation: 44515
There are two ways to enable the JPA repositories:
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.
The @Repository
annotation is not suitable for this usecase and can be removed safely.
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.
Upvotes: 7