Spring not able to locate JpaRepository

You might need to use Spring Boot's @EntityScan annotation if your JPA entities are not in a sub-package of com.example.configuration. I would also recommend that you move your @Configuration off the SpringBootServletInitializer and into its own class.

If you can move your configuration class up a level you can drop the @ComponentScan, @EnableJpaRepositories and @EntityScan annotations all together (see http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-locating-the-main-class)

If @EntityScan doesn't fix things perhaps you could provide an example project that we can look at?


The problem hear that using @EnableJpaRepositories("com.example") the your context when start check for com.example as base package but it don't goes on. In other words the package scan will stop on the com.example level. For a deeper stanning, you have to do a things like this @EnableJpaRepositories("com.example.**"). However in this case the Spring data check all the package com.example and all the sub package. A more correct approch should be write a thik like this @EnableJpaRepositories("com.example.repository") or @EnableJpaRepositories("com.example.repository.**"). In the first case you scan for the repository base package in the second case you scan for the repository and all sub package of repository that in my opinion is the correct approch for this kind of case.

I hope that this can help you