No bean named 'entityManagerFactory' available

0

I'm testing my Spring application with JUnit, however the error is occurring after putting the annotation @EnableJpaRepositories :

  

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available

Configuration class:

@SpringBootApplication
@ComponentScan
@EnableJpaRepositories
public class ExampleApplication {

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

Removing this annotation returns the problem that does not find a dependency for the repository interface.

Obs: The application starts normally, this problem occurs when running the tests, both with Gradle and JUnit.

    
asked by anonymous 12.11.2016 / 20:06

1 answer

0

Answer:

The problem was in the test, you need the @MockBean annotation on top of an object which is a class being a service or repository, ie you need to mock.

Example:

@MockBean
private UserService userService;
    
12.11.2016 / 22:27