Repository navigation
fix: Report duplicate @Bean names on Spring 7 configuration classes even when overriding is allowed (#686) - #692
Merged
Conversation
|
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.
Purpose
The duplicate
@Beanname inspection (#597) stayed silent whenspring.main.allow-bean-definition-overriding=true. On Spring Framework 7 that is wrong for a full@Configurationclass:ConfigurationClassBeanDefinitionReader.isOverriddenByExistingDefinition(spring-context 7.0.9 :337-342) throwsBeanDefinitionOverrideExceptionwhen the class's@ConfigurationhasenforceUniqueMethods = true(the default) or overriding is disallowed, so the property does not rescue it.Change
spring.main.allow-bean-definition-overridingsays (missing,false,trueor unresolvable), with a message that names the Spring 7 rule.enforceUniqueMethodsis read with merged values, asAnnotatedTypeMetadata.getAnnotationAttributes(Configuration)does: a directly declared@Configurationfirst, else the first annotation composed with it; a meta-fixed@Configuration(enforceUniqueMethods = false)and an@AliasFordefault or use-site value count, in Java and Kotlin.@Configuration) and@Configuration(enforceUniqueMethods = false)keep the property rule. When the Spring Framework version cannot be determined and the property istrue, the problem is a warning.[Unreleased]line now states the Spring 7 rule and ends(#597, #686); the inspection description says the same.Framework evidence
Probe on real jars, one
@Configurationclass with@Bean A a()+@Bean("a") A b()(and the same across a class hierarchy):@Configuration@Component)@Configuration(enforceUniqueMethods = false)@Configuration(enforceUniqueMethods = false)@AliasFortoenforceUniqueMethods, defaultfalseunique = true(Java and Kotlin)With overriding disallowed every case fails on both versions.
Not in this PR
Verification
enforceUniqueMethods), each red failing on the problem or message assertion; Java and Kotlin twins; Spring 7 via the Boot 4.1 test library, unknown version via a spring-core jar without coordinates.SpringDuplicateBeanName*classes,MetaAnnotationsHolderMergedValues*45/45.:spring-bootstrap:test --rerun-taskson d1af96b, fresh JUnit XML): spring-core 2413, spring-web 905 (6 skipped), spring-ai 776, jpa 138, spring-data 140, base 35, aop 6, security 6, initializr 5; 0 failures, 0 errors.Main only: the inspection (#669) and
MergedAnnotationAttributes(#673) are not on the release branches.Closes #686