Skip to content

fix(codecs): stop overriding the codecLookup bean definition#15752

Open
codeconsole wants to merge 1 commit into
apache:8.0.xfrom
codeconsole:fix/codecs-lookup-bean-override
Open

fix(codecs): stop overriding the codecLookup bean definition#15752
codeconsole wants to merge 1 commit into
apache:8.0.xfrom
codeconsole:fix/codecs-lookup-bean-override

Conversation

@codeconsole

@codeconsole codeconsole commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

On startup a full Grails application logs a bean-definition override for codecLookup:

Overriding bean definition for bean 'codecLookup' with a different definition:
replacing [... factoryBeanName=org.grails.plugins.codecs.CodecsConfiguration; factoryMethodName=codecLookup ...]
with [Generic bean: class=org.grails.plugins.codecs.DefaultCodecLookup ...]

codecLookup was registered twice, both producing a DefaultCodecLookup:

  • CodecsConfiguration — the @Bean("codecLookup") @Primary auto-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). Because doWithSpring runs after auto-configuration conditions are evaluated, the plugin bean always replaced CodecsConfiguration's — silently dropping its @Primary marker in the process.

Change

Remove the redundant doWithSpring registration so CodecsConfiguration is the single definition. The resulting bean is unchanged — still a DefaultCodecLookup under the name codecLookup — just registered once, with no override.

Two contexts bootstrap from plugins rather than auto-configuration and needed supporting changes:

  • GrailsUnitTest.defineBeans(Object plugin) caught NoSuchFieldException, but clazz.getMethod('getDoWithSpring') throws NoSuchMethodException. A plugin whose doWithSpring() returns null (now including CodecsGrailsPlugin) therefore crashed instead of being skipped. Catch the correct exception.
  • The legacy AbstractGrailsTagTests harnesses (grails-gsp and grails-test-examples/gsp-layout) load plugins but never trigger auto-configuration, so they register codecLookup directly.

Verification

  • Full suite green: 7754 unit + 1812 integration tests, 0 failures/errors.
  • aggregateViolations / codenarcMain for the changed modules — clean.
  • Booted the gsp-sitemesh3 example app with DefaultListableBeanFactory at INFO: the Overriding bean definition for bean 'codecLookup' line is gone, and decoration/codec behavior is unchanged.

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.
@testlens-app

testlens-app Bot commented Jun 22, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 4cfd2f4
▶️ Tests: 49014 executed
⚪️ Checks: 46/46 completed


Learn more about TestLens at testlens.app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant