Skip to content

Add Annotation for bean overriding [SPR-17519] #22051

@spring-projects-issues

Description

@spring-projects-issues

huehnerlady opened SPR-17519 and commented

We like the idea that with spring boot 2.1.0 the default value for the property spring.main.allow-bean-definition-overriding is now set to false.

But this comes with a challenge. We have tests which override one specific bean with a mock for integration testing. Now for these tests we get a BeanOverrideException.
We currently use the workaround with setting the property spring.main.allow-bean-definition-overriding to true for these specific tests, but in the end we might miss other overridden beans in a test which makes the app fail to start later. So we have to add another (expensive) Integration test that checks whether the app starts up without any errors.

So my proposal is to add an annotation - kind of similar to @Primary, that says that you actively want to override ONE SPECIFIC bean and make THIS bean primary.

Other idea is to just have an annotation to allow ONE SPECIFIC bean to be overridden and add the @Primary annotation as well.

What do you think?


Reference URL: spring-projects/spring-boot#15216 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions