|
41 | 41 | import org.springframework.beans.factory.config.DependencyDescriptor;
|
42 | 42 | import org.springframework.beans.factory.config.ListFactoryBean;
|
43 | 43 | import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
| 44 | +import org.springframework.beans.factory.support.BeanDefinitionOverrideException; |
44 | 45 | import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
45 | 46 | import org.springframework.beans.factory.support.RootBeanDefinition;
|
46 | 47 | import org.springframework.beans.testfixture.beans.ITestBean;
|
@@ -219,6 +220,12 @@ void configurationWithNullReference() {
|
219 | 220 | assertThat(foo.getSpouse()).isNull();
|
220 | 221 | }
|
221 | 222 |
|
| 223 | + @Test // gh-33330 |
| 224 | + void configurationWithMethodNameMismatch() { |
| 225 | + assertThatExceptionOfType(BeanDefinitionOverrideException.class) |
| 226 | + .isThrownBy(() -> initBeanFactory(ConfigWithMethodNameMismatch.class)); |
| 227 | + } |
| 228 | + |
222 | 229 | @Test
|
223 | 230 | void configurationWithAdaptivePrototypes() {
|
224 | 231 | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
@@ -352,6 +359,7 @@ private DefaultListableBeanFactory initBeanFactory(Class<?>... configClasses) {
|
352 | 359 | String configBeanName = configClass.getName();
|
353 | 360 | factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
|
354 | 361 | }
|
| 362 | + factory.setAllowBeanDefinitionOverriding(false); |
355 | 363 | ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
|
356 | 364 | ccpp.postProcessBeanDefinitionRegistry(factory);
|
357 | 365 | ccpp.postProcessBeanFactory(factory);
|
@@ -526,6 +534,19 @@ public TestBean bar() {
|
526 | 534 | }
|
527 | 535 |
|
528 | 536 |
|
| 537 | + @Configuration |
| 538 | + static class ConfigWithMethodNameMismatch { |
| 539 | + |
| 540 | + @Bean(name = "foo") public TestBean foo() { |
| 541 | + return new SpousyTestBean("foo"); |
| 542 | + } |
| 543 | + |
| 544 | + @Bean(name = "foo") public TestBean fooX() { |
| 545 | + return new SpousyTestBean("fooX"); |
| 546 | + } |
| 547 | + } |
| 548 | + |
| 549 | + |
529 | 550 | @Scope("prototype")
|
530 | 551 | static class AdaptiveInjectionPoints {
|
531 | 552 |
|
|
0 commit comments