I'm writing integration tests for Spring Boot (v2.6.11) application, and I found some thing interesting.
This works fine, application can start up
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import static com.example.SomeIntegrationTest.Config;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@SpringBootTest(
classes = Config.class,
webEnvironment = RANDOM_PORT,
properties = {"spring.application.name=exception-handler-advice-integration-tests" }
)
class SomeIntegrationTest {
@Test
void testWhatever() {
}
@Configuration(proxyBeanMethods = false)
@EnableAutoConfiguration
static class Config {
}
}
But if I change the import order
import static com.example.SomeIntegrationTest.Config;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
@SpringBootTest(
classes = Config.class,
webEnvironment = RANDOM_PORT,
properties = {"spring.application.name=whatever" }
)
class SomeIntegrationTest {
@Test
void testWhatever() {
}
@Configuration(proxyBeanMethods = false)
@EnableAutoConfiguration
static class Config {
}
}
And there will be a compile-time error
.../src/test/java/com/example/SomeIntegrationTest.java:22: error: cannot find symbol
@Configuration(proxyBeanMethods = false)
^
symbol: class Configuration
location: class SomeIntegrationTest
.../src/test/java/com/example/SomeIntegrationTest.java:23: error: cannot find symbol
@EnableAutoConfiguration
^
symbol: class EnableAutoConfiguration
location: class SomeIntegrationTest
If I don't use static import
@SpringBootTest(
classes = SomeIntegrationTest.Config.class,
webEnvironment = RANDOM_PORT,
properties = {"spring.application.name=whatever" }
)
And this will work
I think it's more like a javac problem :)
Comment From: wilkinsona
I think it's more like a
javacproblem.
I agree. We've seen this in our own code on occasion but have never managed to recreate it in an isolated example which has prevented us from reporting it to the OpenJDK team. It looks like you may have found such an example. Can you please open an OpenJDK issue and provide them with a minimal sample that reproduces the problem? They'll need to know the dependencies and specific version of Java that you're using.