Merge branch '6.2.x'

This commit is contained in:
Sam Brannen
2025-10-15 12:49:16 +02:00
3 changed files with 27 additions and 40 deletions
@@ -423,35 +423,28 @@ class ConfigurationClassPostProcessorTests {
beanFactory.setAllowBeanDefinitionOverriding(false);
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
assertThatIllegalStateException()
assertThatExceptionOfType(BeanDefinitionStoreException.class)
.isThrownBy(() -> pp.postProcessBeanFactory(beanFactory))
.withMessage("Failed to load bean definitions for configuration class '%s'", SingletonBeanConfig.class.getName())
.havingCause()
.isInstanceOf(BeanDefinitionStoreException.class)
.withMessageContainingAll(
"bar",
"SingletonBeanConfig",
TestBean.class.getName()
);
.withMessageContainingAll(
"bar",
"SingletonBeanConfig",
TestBean.class.getName()
);
}
@Test // gh-25430
void detectAliasOverride() {
Class<?> configClass = SecondConfiguration.class;
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
DefaultListableBeanFactory beanFactory = context.getDefaultListableBeanFactory();
beanFactory.setAllowBeanDefinitionOverriding(false);
context.register(FirstConfiguration.class, configClass);
context.register(FirstConfiguration.class, SecondConfiguration.class);
assertThatIllegalStateException().isThrownBy(context::refresh)
.withMessage("Failed to load bean definitions for configuration class '%s'", configClass.getName())
.havingCause()
.isExactlyInstanceOf(IllegalStateException.class)
.withMessageContainingAll(
"alias 'taskExecutor'",
"name 'applicationTaskExecutor'",
"bean definition 'taskExecutor'"
);
.withMessageContainingAll(
"alias 'taskExecutor'",
"name 'applicationTaskExecutor'",
"bean definition 'taskExecutor'"
);
context.close();
}
@@ -1245,11 +1238,8 @@ class ConfigurationClassPostProcessorTests {
@Test
void nameClashBetweenConfigurationClassAndBean() {
assertThatIllegalStateException()
.isThrownBy(() -> new AnnotationConfigApplicationContext(MyTestBean.class))
.withMessage("Failed to load bean definitions for configuration class '%s'", MyTestBean.class.getName())
.havingCause()
.isInstanceOf(BeanDefinitionStoreException.class);
assertThatExceptionOfType(BeanDefinitionStoreException.class)
.isThrownBy(() -> new AnnotationConfigApplicationContext(MyTestBean.class));
}
@Test
@@ -60,7 +60,6 @@ import org.springframework.context.support.GenericApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Miscellaneous system tests covering {@link Bean} naming, aliases, scoping and
@@ -220,12 +219,8 @@ class ConfigurationClassProcessingTests {
@Test // gh-33330
void configurationWithMethodNameMismatch() {
Class<?> configClass = ConfigWithMethodNameMismatch.class;
assertThatIllegalStateException()
.isThrownBy(() -> initBeanFactory(false, configClass))
.withMessage("Failed to load bean definitions for configuration class '%s'", configClass.getName())
.havingCause()
.isInstanceOf(BeanDefinitionOverrideException.class);
assertThatExceptionOfType(BeanDefinitionOverrideException.class)
.isThrownBy(() -> initBeanFactory(false, ConfigWithMethodNameMismatch.class));
}
@Test // gh-33920