Can I tell spring-boot to automatically resolve the requested locale by a queryparameter, eg &lang=en?
I would like to give the query param precedence over Accept-Language parameter.
I found the following two properties, but nothing about a query param.
spring.mvc.locale= # Locale to use. By default, this locale is overridden by the "Accept-Language" header.
spring.mvc.locale-resolver=accept-header # Define how the locale should be resolved.
I tried as follows, which gives an exception:
@Configuration
public class AppConfig extends WebMvcConfigurerAdapter {
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
return lci;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
}
Results in:
java.lang.UnsupportedOperationException: Cannot change HTTP accept header - use a different locale resolution strategy
formatcan be used to set the response output format.LocaleResolver.spring.mvc.locale-resolveroffers onyaccept-headerorfixed, which is both not what I want.LocaleResolveras you would in a regular spring application.