Repository navigation
fix: Report duplicate @Bean names by Spring Framework version and collision kind (#689) - #695
Merged
imuromtsev merged 8 commits intoOct 14, 2026
Conversation
|
imuromtsev
added this pull request to stack #699
October 14, 2026 06:45
imuromtsev
deleted the
imuromtsev/duplicate-bean-name-before-spring-6-2
branch
October 14, 2026 06:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #692 (#686): base branch
imuromtsev/spring7-bean-override-rule. Merge #692 first; GitHub then retargets this PR tomain.Purpose
The duplicate
@Beanname inspection (#597, unreleased) reports "fails Spring Boot startup" for every pair of@Beanmethods that declare the same bean name. Probes on realspring-contextjars show that this holds only from Spring Framework 6.2.0 for primary names, from 6.0 for a name that is the primary name of one method and an alias of the other, and on every version for an alias shared by both methods. Before that, Spring starts and silently ignores one of the two methods, so the error is a false positive on Spring Boot 2.x–3.3.x.Change
The verdict is decided per collision, by its kind (the name is the primary name — the first declared
@Beanname, else the method name — of both methods, of one, or of neither), the fullspring-coreversion andspring.main.allow-bean-definition-overriding:falsetrue@ConfigurationwithenforceUniqueMethodsenforceUniqueMethods = falseSpringBootUtil.getSpringCoreVersion(cached like the major version, which now derives from it).(#597, #686, #689).Framework evidence
Probes with
AnnotationConfigApplicationContext, one configuration class:@Bean a()+@Bean("a") b(), overriding disallowed@Configuration)@Bean({"a","svc"}) x()+@Bean("svc") y(), disallowed{"a","svc"}+{"b","svc"}, disallowedLite classes (
@Componentwith@Beanmethods) behave like full@Configurationclasses before 6.2.0.Verification
spring-coreversion: Boot 2.7.18 → 5.3.31, 3.1.1 → 6.0.10, 3.4.0 → 6.2.0, 4.1.0 → 7.0.8, and aspring-corejar without coordinates for an unknown version), each failing on its severity or message assertion.SpringDuplicateBeanName*tests.:spring-bootstrap:test --rerun-taskson f923cdc, fresh JUnit XML): spring-core 2463, spring-web 905 (6 skipped), spring-ai 776, spring-data 140, jpa 138, base 35, aop 6, security 6, initializr 5 — 0 failures except one ExodusThreadLeakTrackerleak assertion inSpringBootApplicationMcpToolsetTraceFunctionalRouteTest, which passed 40/40 when rerun alone (known flake).Main only: the inspection (#669) is not on the release branches.
Follow-ups
Closes #689