Internationalization with spring mvc

2019-08-04 13:48发布

问题:

I'm new to spring, i have a working bilingual application based on Spring MVC, and in order to customize the UI ( css & js ) , i've added this to my Spring-MVC configuration file :

<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />

The css/js intégration worked well, but the Internationalization wasn't, when i delete the resources tag, the internationalization starts working but the css includes doesn't...

this is my project tree :

I believe that there is some kind of conflict Between the two resources folders, but i don't know how to solve this ... Thank you !

EDIT : Internationalization XML Config in SpringMVC-XML-Config File:

<!-- Spring Internationalizations -->

<bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:messages" />
    <property name="defaultEncoding" value="UTF-8" />
</bean>

<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
    <property name="defaultLocale" value="en" />
</bean>

<bean id="localeChangeInterceptor"
    class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="language" />
</bean>
<bean id="handlerMapping"
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="interceptors">
        <ref bean="localeChangeInterceptor" />
    </property>    
</bean>

回答1:

Issue Solved by surrounding the LocaleChangeInterceptor with mvc interceptors tags :

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

the problem comes after adding <mvc:annotation-driven/> because it declares its own annotation handler mapping filter (LocaleChangeInterceptor was ignored ), So I had to use the <mvc:interceptors> to register the I18N interceptor bean in my Servlet Dispatcher.