Internationalization with spring mvc

2019-08-04 13:38发布

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 :

enter image description here

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条回答
等我变得足够好
2楼-- · 2019-08-04 13:48

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.

查看更多
登录 后发表回答