codeconsole opened a new pull request, #15775:
URL: https://github.com/apache/grails-core/pull/15775

   ## What
   
   `ControllersAutoConfiguration` defines its own `dispatcherServlet` (a 
`GrailsDispatcherServlet`) and `dispatcherServletRegistration` beans, but it is 
**not** ordered before Spring Boot's `DispatcherServletAutoConfiguration`. As a 
result Spring Boot registers its own beans first and Grails *overrides* them on 
startup:
   
   ```
   INFO  o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for 
bean 'dispatcherServlet' with a different definition:
     replacing [... 
DispatcherServletAutoConfiguration$DispatcherServletConfiguration ...]
     with      [... ControllersAutoConfiguration ...]
   INFO  o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for 
bean 'dispatcherServletRegistration' with a different definition:
     replacing [... 
DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration 
...]
     with      [... ControllersAutoConfiguration ...]
   ```
   
   This emits two INFO `Overriding bean definition` messages and depends on 
`spring.main.allow-bean-definition-overriding` to win.
   
   ## Change
   
   Add `DispatcherServletAutoConfiguration` to the existing 
`@AutoConfiguration(before = …)` list:
   
   ```java
   @AutoConfiguration(
           before = {DispatcherServletAutoConfiguration.class, 
HttpEncodingAutoConfiguration.class, WebMvcAutoConfiguration.class},
           after = {GrailsDomainClassAutoConfiguration.class}
   )
   ```
   
   Grails now registers `dispatcherServlet` / `dispatcherServletRegistration` 
first, so Spring Boot's `DefaultDispatcherServletCondition` and 
`DispatcherServletRegistrationCondition` find the existing beans and **back 
off** through their own conditions rather than being overridden.
   
   ## Why it's safe
   
   - Runtime behavior is unchanged — `GrailsDispatcherServlet` still handles 
requests in both cases; only the registration mechanism changes (back-off 
instead of override).
   - Converts an override into idiomatic auto-configuration ordering and 
removes two INFO log lines, reducing reliance on bean-definition overriding.
   
   ## Verification
   
   - `./gradlew :grails-controllers:compileGroovy` — BUILD SUCCESSFUL.
   - Mechanism follows Spring Boot's `DefaultDispatcherServletCondition` (backs 
off when a `dispatcherServlet`-named `DispatcherServlet` bean already exists).
   
   https://claude.ai/code/session_01QWB8jcKezznEJTLND9Vrye
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to