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

   ## What
   
   `I18nAutoConfiguration.localeResolver()` registers the `localeResolver` bean 
**unconditionally**. As a result, any application- or plugin-supplied 
`LocaleResolver` overrides the framework default — a bean-definition override 
warning on startup by default, and a hard startup failure when 
`spring.main.allow-bean-definition-overriding=false`.
   
   This adds `@ConditionalOnMissingBean(name = "localeResolver")` so the Grails 
default backs off cleanly when the application already defines one. This 
mirrors Spring Boot's own `WebMvcAutoConfiguration.localeResolver()`, which is 
`@ConditionalOnMissingBean` for exactly this reason — registering it 
unconditionally is the divergence.
   
   ```java
   @Bean(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME)
   @ConditionalOnMissingBean(name = DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME)
   public LocaleResolver localeResolver() {
       return new SessionLocaleResolver();
   }
   ```
   
   ## Why keyed on the name, not the type
   
   `DispatcherServlet` resolves the locale resolver by the fixed bean name 
`DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME` (`"localeResolver"`). A 
`LocaleResolver` bean registered under a different name is never the one 
actually used, so keying the condition on the bean name matches the real lookup 
semantics — a by-type condition could back off for an unrelated resolver bean 
that `DispatcherServlet` ignores.
   
   ## Scope
   
   The sibling beans in the same class (`localeChangeInterceptor`, 
`messageSource`) are also registered unconditionally; this PR is intentionally 
scoped to `localeResolver` only. Happy to extend if maintainers prefer.
   


-- 
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