8.0.x FIX: Overriding bean definition for bean 'dispatcherServlet' with a different definition#15775
Open
codeconsole wants to merge 1 commit into
Open
Conversation
ControllersAutoConfiguration defines its own `dispatcherServlet` (a GrailsDispatcherServlet) and `dispatcherServletRegistration` beans, but it was not ordered before Spring Boot's DispatcherServletAutoConfiguration. Spring Boot therefore registered its own beans first and Grails overrode them, producing two INFO "Overriding bean definition for bean 'dispatcherServlet'/'dispatcherServletRegistration'" messages on startup and relying on bean-definition overriding to win. Add DispatcherServletAutoConfiguration to the auto-configuration `before` list so Grails registers these beans first. Spring Boot's DefaultDispatcherServletCondition and DispatcherServletRegistrationCondition then see the existing beans and back off via their own conditions instead of being overridden. Runtime behavior is unchanged - GrailsDispatcherServlet still handles requests - but the override and its log noise are eliminated.
15b6cd0 to
c87af0f
Compare
✅ All tests passed ✅🏷️ Commit: c87af0f 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.
What
ControllersAutoConfigurationdefines its owndispatcherServlet(aGrailsDispatcherServlet) anddispatcherServletRegistrationbeans, but it is not ordered before Spring Boot'sDispatcherServletAutoConfiguration. As a result Spring Boot registers its own beans first and Grails overrides them on startup:This emits two INFO
Overriding bean definitionmessages and depends onspring.main.allow-bean-definition-overridingto win.Change
Add
DispatcherServletAutoConfigurationto the existing@AutoConfiguration(before = …)list:Grails now registers
dispatcherServlet/dispatcherServletRegistrationfirst, so Spring Boot'sDefaultDispatcherServletConditionandDispatcherServletRegistrationConditionfind the existing beans and back off through their own conditions rather than being overridden.Why it's safe
GrailsDispatcherServletstill handles requests in both cases; only the registration mechanism changes (back-off instead of override).Verification
./gradlew :grails-controllers:compileGroovy— BUILD SUCCESSFUL.DefaultDispatcherServletCondition(backs off when adispatcherServlet-namedDispatcherServletbean already exists).