Hello,
We are trying to adopt Spring Boot 2.1 (currently we are on 2.0.2) but we face issues. Here is an example:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestApplication.class }, webEnvironment = WebEnvironment.NONE)
@Transactional
public class SampleIT {
@Autowired
private TestEntityRepository testEntityRepository;
@Autowired
private TransactionalTestService transactionalTestService;
...
}
Here is the stacktrace:
java.lang.NullPointerException: null
at org.springframework.boot.test.autoconfigure.properties.AnnotationsPropertySource.collectProperties(AnnotationsPropertySource.java:73)
at org.springframework.boot.test.autoconfigure.properties.AnnotationsPropertySource.collectProperties(AnnotationsPropertySource.java:79)
at org.springframework.boot.test.autoconfigure.properties.AnnotationsPropertySource.getProperties(AnnotationsPropertySource.java:64)
at org.springframework.boot.test.autoconfigure.properties.AnnotationsPropertySource.<init>(AnnotationsPropertySource.java:59)
at org.springframework.boot.test.autoconfigure.properties.AnnotationsPropertySource.<init>(AnnotationsPropertySource.java:54)
at org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizerFactory.createContextCustomizer(PropertyMappingContextCustomizerFactory.java:37)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.getContextCustomizers(AbstractTestContextBootstrapper.java:404)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:376)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildDefaultMergedContextConfiguration(AbstractTestContextBootstrapper.java:312)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:265)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:108)
at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.buildTestContext(SpringBootTestContextBootstrapper.java:99)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:139)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:124)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:151)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:142)
at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
at sun.reflect.GeneratedConstructorAccessor56.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
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)
The problem occurs during because mergedAnnotations
return [null]
for the Transactional annotation.
Have you seen similar problem before? Do you need more input?
Best regards, Yana
Comment From: wilkinsona
Thanks for the report. I'm struggling to see how a null
can end up in the list that's returned by getMergedAnnotations()
and my attempts to reproduce the problem have been unsuccessful. Protecting against null
in AnnotationsPropertySource
may be addressing a symptom of the problem rather than the cause so I'd like to understand what's causing the problem in your situation. Can you please provide a complete, minimal example (something that we can unzip or git clone
and run) that reproduces the problem?
Comment From: yanavasileva
Hi,
Thank you for your fast reply.
I created an example here:
https://github.com/yanavasileva/spring-boot-test
just run mvn install
Thanks, Yana
Comment From: philwebb
I think the root cause of the null
is a Spring Framework issue (see SPR-17495 for a description). We should probably also guard against a null
result when building the mergedAnnotations
list regardless.
Comment From: yanavasileva
Thanks, I see that you added the null check in 1.5, is it possible to do it for 2.1 (maybe 2.1.1) as well?
Comment From: wilkinsona
The fix has already been merged forwards into 2.0.x and 2.1.x.
Comment From: yanavasileva
Great, thank you!
Comment From: deerball
I found this issue in 1.5.9 release version. Will the fix be merged to this release?
Comment From: wilkinsona
Once a release has been made, it can't be changed. The fix for this issue is in 1.5.18 and won't become part of any earlier 1.5.x releases. Also, please not that 1.5.x is no longer supported and you should upgrade to 2.x as soon as possible.