Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot change HTTP accept header - use a different locale resolution strategy

I follow Spring mvc course on Pluralsight, and I have "Cannot change HTTP accept header - use a different locale resolution strategy" this error when running my application. Before this, I added theese beans to servlet-config.xml

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="language" />
</mvc:interceptors>         

<bean id="localResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" p:defaultLocale="en" />

In resource folder I have two files. messages_es.properties and messages.properties. One hasgoal.text=Minutos Ejercicio para el día de hoy: and other goal.text=Minutes Exercise For The Day Today: So the target is to choose the language.

And in jsp file I have this line about it

Language : <a href="?language=en">English</a> | <a href="?language=es">Spanish </a>

So how can I make it work correctly?

like image 708
Vladyslav K Avatar asked May 20 '14 17:05

Vladyslav K


2 Answers

Change the bean id from "localResolver" to "localeResolver"

like image 99
Storm Avatar answered Nov 14 '22 16:11

Storm


I solved this issue by naming the method as localeResolver using the solution provided here Spring 4 i18n & l10n (Cannot change HTTP accept header)

@Bean
public LocaleResolver localeResolver()
{
    final SessionLocaleResolver localeResolver = new SessionLocaleResolver();
    localeResolver.setDefaultLocale(new Locale("en", "US"));
    return localeResolver;
}
like image 30
Gopi Palamalai Avatar answered Nov 14 '22 16:11

Gopi Palamalai