Skip to content

Commit 659b459

Browse files
committed
Make the auto-configured LocaleContextResolver conditional on missing bean
Closes gh-23419
1 parent 2019371 commit 659b459

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter;
7070
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
7171
import org.springframework.web.reactive.result.view.ViewResolver;
72+
import org.springframework.web.server.i18n.LocaleContextResolver;
7273

7374
/**
7475
* {@link EnableAutoConfiguration Auto-configuration} for {@link EnableWebFlux WebFlux}.
@@ -264,6 +265,13 @@ protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
264265
return super.createRequestMappingHandlerMapping();
265266
}
266267

268+
@Bean
269+
@Override
270+
@ConditionalOnMissingBean
271+
public LocaleContextResolver localeContextResolver() {
272+
return super.localeContextResolver();
273+
}
274+
267275
}
268276

269277
@Configuration(proxyBeanMethods = false)

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
7474
import org.springframework.web.reactive.result.view.ViewResolutionResultHandler;
7575
import org.springframework.web.reactive.result.view.ViewResolver;
76+
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
77+
import org.springframework.web.server.i18n.LocaleContextResolver;
7678
import org.springframework.web.util.pattern.PathPattern;
7779

7880
import static org.assertj.core.api.Assertions.assertThat;
@@ -452,6 +454,13 @@ void welcomePageHandlerMapping() {
452454
});
453455
}
454456

457+
@Test
458+
void customLocaleContextResolver() {
459+
this.contextRunner.withUserConfiguration(LocaleContextResolverConfiguration.class)
460+
.run((context) -> assertThat(context).hasSingleBean(LocaleContextResolver.class)
461+
.hasBean("customLocaleContextResolver"));
462+
}
463+
455464
private Map<PathPattern, Object> getHandlerMap(ApplicationContext context) {
456465
HandlerMapping mapping = context.getBean("resourceHandlerMapping", HandlerMapping.class);
457466
if (mapping instanceof SimpleUrlHandlerMapping) {
@@ -676,4 +685,14 @@ public Example parse(String source, Locale locale) {
676685

677686
}
678687

688+
@Configuration(proxyBeanMethods = false)
689+
static class LocaleContextResolverConfiguration {
690+
691+
@Bean
692+
LocaleContextResolver customLocaleContextResolver() {
693+
return new AcceptHeaderLocaleContextResolver();
694+
}
695+
696+
}
697+
679698
}

0 commit comments

Comments
 (0)