fix(codecs): stop overriding the codecLookup bean definition#15752
Open
codeconsole wants to merge 1 commit into
Open
fix(codecs): stop overriding the codecLookup bean definition#15752codeconsole wants to merge 1 commit into
codeconsole wants to merge 1 commit into
Conversation
CodecsConfiguration (auto-config) already registers the @primary codecLookup bean in every production context, but CodecsGrailsPlugin's doWithSpring registered a second codecLookup, which Grails logged as a bean-definition override at startup: Overriding bean definition for bean 'codecLookup' ... Remove the redundant doWithSpring registration so CodecsConfiguration is the single definition. Supporting changes for the two contexts that bootstrap from plugins rather than auto-configuration: - GrailsUnitTest.defineBeans caught NoSuchFieldException, but getMethod('getDoWithSpring') throws NoSuchMethodException, so a plugin whose doWithSpring() returns null (now including CodecsGrailsPlugin) crashed instead of being skipped. Catch the correct exception. - The legacy AbstractGrailsTagTests harnesses load plugins but not auto-configuration, so they register codecLookup directly.
✅ All tests passed ✅🏷️ Commit: 4cfd2f4 Learn more about TestLens at testlens.app. |
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.
Summary
On startup a full Grails application logs a bean-definition override for
codecLookup:codecLookupwas registered twice, both producing aDefaultCodecLookup:CodecsConfiguration— the@Bean("codecLookup") @Primaryauto-configuration bean (loaded in every production context, including grails-testing-support and plain Spring Boot).CodecsGrailsPlugin.doWithSpring— a second registration that overrode the auto-config one (the log). BecausedoWithSpringruns after auto-configuration conditions are evaluated, the plugin bean always replacedCodecsConfiguration's — silently dropping its@Primarymarker in the process.Change
Remove the redundant
doWithSpringregistration soCodecsConfigurationis the single definition. The resulting bean is unchanged — still aDefaultCodecLookupunder the namecodecLookup— just registered once, with no override.Two contexts bootstrap from plugins rather than auto-configuration and needed supporting changes:
GrailsUnitTest.defineBeans(Object plugin)caughtNoSuchFieldException, butclazz.getMethod('getDoWithSpring')throwsNoSuchMethodException. A plugin whosedoWithSpring()returnsnull(now includingCodecsGrailsPlugin) therefore crashed instead of being skipped. Catch the correct exception.AbstractGrailsTagTestsharnesses (grails-gsp and grails-test-examples/gsp-layout) load plugins but never trigger auto-configuration, so they registercodecLookupdirectly.Verification
aggregateViolations/codenarcMainfor the changed modules — clean.gsp-sitemesh3example app withDefaultListableBeanFactoryat INFO: theOverriding bean definition for bean 'codecLookup'line is gone, and decoration/codec behavior is unchanged.