We have an application that relies on Spring Boot 2.0. We are in the process of migrating it to JDK11 from JDK8. This also enabled us to update Spring Boot from 2.0 to 2.1. After reading through the changelog, it appeared there was any major change that needed for us.
Now the problem lies in where some test classes are annotated with both @SpringBootTest
and @DataJpaTest
. As per this and as well as the documentation, we are not supposed to use both together and instead we changed @DataJpaTest
to @AutoConfigureTestDatabase
. Here is how the code is:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {A.class, B.class}, properties = {
"x=xxx",
"y=yyy"
})
@AutoConfigureTestDatabase // Used to be @DataJpaTest
@EnableJpaRepositories("com.test")
@EntityScan("com.test")
public class Test {
@TestConfiguration
public static class TestConfig {
// Some beans returning
}
// Tests
}
Now, we end up with the following error:
NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
So as per this answer, we did something like this:
@EnableJpaRepositories(basePackages="com.test", entityManagerFactoryRef="entityManagerFactory")
Even after this we still end up with the same error. Is this the right way to remove @DataJpaTest
? Or do we need to remove @SpringBootTest
and do something else? Any sort of guidance is much appreciated.