Skip to content

Unable to find a @SpringBootConfiguration results in misleading error message #43357

@quaff

Description

@quaff

Exception is raised if the test is not located in the same or sub package of @SpringBootApplication main class, even if I use @ContextConfiguration or @SpringBootTest(classes=...) according to the suggestion in exception message.

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test	at org.springframework.util.Assert.state(Assert.java:76)	at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.findConfigurationClass(SpringBootTestContextBootstrapper.java:246)	at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.getOrFindConfigurationClasses(SpringBootTestContextBootstrapper.java:233)	at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.processMergedContextConfiguration(SpringBootTestContextBootstrapper.java:150)	at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:351)	at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildDefaultMergedContextConfiguration(AbstractTestContextBootstrapper.java:267)	at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:215)	at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:108)	at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.buildTestContext(SpringBootTestContextBootstrapper.java:111)	at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:142)	at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:126)	at org.springframework.test.context.junit.jupiter.SpringExtension.getTestContextManager(SpringExtension.java:366)	at org.springframework.test.context.junit.jupiter.SpringExtension.beforeAll(SpringExtension.java:131)	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) 

the reproducer project configuration-class-not-found.zip

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions