Skip to content

BeanDefinitionOverrideException not thrown as expected #28970

Closed as not planned
Closed as not planned
@ipavkovic

Description

@ipavkovic

environment: spring boot 2.6.10

define a demo app with following configuration class:

@Configuration
public class DemoConfig {

    @Bean("aaa")
    public String foo() {
        return "foo";
    }

    @Bean("aaa")
    public String bar() {
        return "bar";
    }
}

should be: BeanDefinitionOverrideException
is: bean named "aaa" added to bean context (with value "foo"), method bar() never added to bean definition

debugging shows a return statement here, that seems to the cuprit.

if (isOverriddenByExistingDefinition(beanMethod, beanName)) {
if (beanName.equals(beanMethod.getConfigurationClass().getBeanName())) {
throw new BeanDefinitionStoreException(beanMethod.getConfigurationClass().getResource().getDescription(),
beanName, "Bean name derived from @Bean method '" + beanMethod.getMetadata().getMethodName() +
"' clashes with bean name for containing configuration class; please make those names unique!");
}
return;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions