DataJpaTest fails when updating to SpringBoot 1.5.5.RELEASE
See original GitHub issueI have a working test against an in-memory database with Spring Boot 1.5.4.RELEASE (or 2.0.0.M2) When I upgrade my project to 1.5.5.RELEASE (or 2.0.0.M3) the test fails because it cannot load the application context:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.lang.IllegalStateException: Unable to retrieve @EnableAutoConfiguration base packages
at org.springframework.boot.autoconfigure.AutoConfigurationPackages.get(AutoConfigurationPackages.java:78)
at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.getBasePackages(AbstractRepositoryConfigurationSourceSupport.java:78)
at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport$1.getBasePackages(AbstractRepositoryConfigurationSourceSupport.java:72)
at org.springframework.data.repository.config.RepositoryConfigurationSourceSupport.getCandidates(RepositoryConfigurationSourceSupport.java:75)
at org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport.getRepositoryConfigurations(RepositoryConfigurationExtensionSupport.java:83)
...
Basically, this is my test
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {SamePackageEntity.class})
@DataJpaTest
public class SamePackageEntityTest {
@Autowired
private SamePackageRepository samePackageRepository;
@Test
public void repositoryShouldHaveBeenInitialized() throws Exception {
assertThat( samePackageRepository.count() ).isEqualTo( 0L );
}
}
Is the problem in the update or in my Test?
I’ve added a pull request to spring-boot-issues that reproduces this problem
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Spring Boot Reference Guide
This section provides a brief overview of Spring Boot reference documentation. Think of it as map for the rest of the document. You...
Read more >[Solved]-Hibernate-core error when using spring-boot-starter-data ...
Coding example for the question Hibernate-core error when using spring-boot-starter-data-jpa-Hibernate.
Read more >Spring Boot Starter Test - Maven Repository
Starter for testing Spring Boot applications with libraries including JUnit Jupiter, Hamcrest and Mockito. License, Apache 2.0.
Read more >Spring Boot changelog - Awesome Java - LibHunt
New Features. Provide a property or environment variable to enable DevTools' restarter irrespective of how the application was launched #21424 ...
Read more >io.zonky.test:embedded-database-spring-test 2.1.2 on Maven
Supported versions are Spring 4.3.8+ and Spring Boot 1.4.6+ ... If you are upgrading from the 1.x version, check the release notes.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I still don’t believe there’s anything to fix here. Your application fits the description in this comment I made above. Specifically, there’s no class annotated with
@EnableAutoConfiguration
and you’re trying to use@DataJpaTest
. That only worked previously due to a bug in 1.5.4 and earlier.That shouldn’t be necessary, and is rather odd as you’re referencing an entity in your
@ContextConfiguration
rather than a configuration class. Instead, you should add a main application class annotated with@SpringBootApplication
(or@EnableAutoConfiguration
) as shown in the following diff:Upon closer inspection, I’ve just noticed that you’re subclassing
JpaBaseConfiguration
as you want to use Eclipse Link rather than Hibernate. For that purpose, it isn’t discouraged.@wilkinsona Thanks for the tips! Replaced
@SpringBootTest
by@ContextConfiguration
.What would be your recommendation for auto configurations? Create my own one and exclude the other one e.g.
JpaBaseConfiguration
?and: would you mind to reopen this issue, till it is fixed?