Improve exception message to include affected configuration class
Closes gh-32998
This commit is contained in:
parent
a6fb7e99a0
commit
89e894205a
|
|
@ -323,7 +323,8 @@ class ConfigurationClassParser {
|
|||
List<Condition> registerBeanConditions = collectRegisterBeanConditions(configClass);
|
||||
if (!registerBeanConditions.isEmpty()) {
|
||||
throw new ApplicationContextException(
|
||||
"Component scan could not be used with conditions in REGISTER_BEAN phase: " + registerBeanConditions);
|
||||
"Component scan for configuration class [%s] could not be used with conditions in REGISTER_BEAN phase: %s"
|
||||
.formatted(configClass.getMetadata().getClassName(), registerBeanConditions));
|
||||
}
|
||||
for (AnnotationAttributes componentScan : componentScans) {
|
||||
// The config class is annotated with @ComponentScan -> perform the scan immediately
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.annotation.Gh23206Tests.ConditionalConfiguration.NestedConfiguration;
|
||||
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
|
||||
|
|
@ -39,7 +40,9 @@ public class Gh23206Tests {
|
|||
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(context::refresh)
|
||||
.withMessageContaining(ConditionalComponentScanConfiguration.class.getName())
|
||||
.havingCause().isInstanceOf(ApplicationContextException.class)
|
||||
.withMessageContaining("Component scan could not be used with conditions in REGISTER_BEAN phase");
|
||||
.withMessageStartingWith("Component scan for configuration class [")
|
||||
.withMessageContaining(ConditionalComponentScanConfiguration.class.getName())
|
||||
.withMessageContaining("could not be used with conditions in REGISTER_BEAN phase");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -49,7 +52,9 @@ public class Gh23206Tests {
|
|||
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(context::refresh)
|
||||
.withMessageContaining(ConditionalConfiguration.class.getName())
|
||||
.havingCause().isInstanceOf(ApplicationContextException.class)
|
||||
.withMessageContaining("Component scan could not be used with conditions in REGISTER_BEAN phase");
|
||||
.withMessageStartingWith("Component scan for configuration class [")
|
||||
.withMessageContaining(NestedConfiguration.class.getName())
|
||||
.withMessageContaining("could not be used with conditions in REGISTER_BEAN phase");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue