Closed
Description
Running a WebMvcTest
in a native image fails with
Failures (1):
JUnit Jupiter:DemoControllerTests
ClassSource [className = 'com.example.demo.DemoControllerTests', filePosition = null]
=> java.lang.IllegalStateException: Unable to instantiate DeterminableImportSelector org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelector
org.springframework.boot.test.context.ImportsContextCustomizer$ContextCustomizerKey.instantiate(ImportsContextCustomizer.java:316)
org.springframework.boot.test.context.ImportsContextCustomizer$ContextCustomizerKey.determineImports(ImportsContextCustomizer.java:296)
org.springframework.boot.test.context.ImportsContextCustomizer$ContextCustomizerKey.determineImports(ImportsContextCustomizer.java:276)
org.springframework.boot.test.context.ImportsContextCustomizer$ContextCustomizerKey.<init>(ImportsContextCustomizer.java:236)
org.springframework.boot.test.context.ImportsContextCustomizer.<init>(ImportsContextCustomizer.java:71)
[...]
Caused by: java.lang.NoSuchMethodException: org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelector.<init>()
java.lang.Class.getConstructor0(DynamicHub.java:3585)
java.lang.Class.getDeclaredConstructor(DynamicHub.java:2754)
org.springframework.boot.test.context.ImportsContextCustomizer$ContextCustomizerKey.instantiate(ImportsContextCustomizer.java:311)
[...]
This can be reproduced using this sample. This code seems to be required to build a suitable MergedContextConfiguration
but I wonder if it should be running at all since the context has already been fully prepared at this point. See also #32420