2016-02-05 76 views
0
<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
      xmlns:context="http://www.springframework.org/schema/context" 
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" 
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd 
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"> 

      <context:component-scan base-package="in.controllers" /> 

      <context:annotation-config /> 

      <!-- This tag adds DefaultAnnotationHandlerMapping. If <mvc:resources /> 
       is tag is used, it will add the ResourceHttpRequestHandler, which will break 
       the existing default handlers added by the spring. So it is required to add 
       the handler mapping explicitly or add <mvc:annotation-driven /> tag. --> 
      <mvc:annotation-driven /> 

      <mvc:resources location="/static/" mapping="/static/**" /> 

      <!-- <bean id="viewNameTranslator" --> 
      <!-- class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator" 
       /> --> 

     <!--  If you do not register any “localeResolver”, the default AcceptHeaderLocaleResolver will be used, --> 
     <!--  which resolves the locale by checking the accept-language header in the HTTP request. --> 

      <bean id="multipartResolver" 
       class="org.springframework.web.multipart.commons.CommonsMultipartResolver" /> 

      <bean id="viewResolver" 
       class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <!--  <property name="order" value="0" /> --> 
       <property name="viewClass" 
        value="org.springframework.web.servlet.view.tiles3.TilesView" /> 
      </bean> 
      <bean id="tilesConfigurer" 
       class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> 
       <property name="definitions" value="/WEB-INF/tiles-defs.xml" /> 
      </bean> 
      <!-- for bilingual ..these are the settings ....starts... --> 

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

      <bean id="localeChangeInterceptor" 
       class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
       <property name="paramName" value="locale"></property> 
      </bean> 

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

      <!-- the “order” property, where the lower order value has the higher priority. --> 
      <bean id="handlerMapping" 
       class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> 
     <!--  <property name="order" value="1" /> --> 
       <property name="interceptors"> 
        <ref bean="localeChangeInterceptor"></ref> 
       </property> 
      </bean> 
      <!-- for bilingual ..these are the settings ....ends... --> 
     </beans> 

..国际化不是Spring MVC的工作和瓷砖支持

以上是我的春天的servlet的XML文件。在我的JSP

<a href="?locale=en">English</a> <a href="?locale=kan"> 

国际化不能正常工作..please使用此帮助..所有消息属性文件存在..但仍i18n不工作..请帮助..

+0

删除'handlerMapping'它打破东西。您正在使用'',然后使用''来注册拦截器。 –

+0

你的建议解决了这个问题.....谢谢你veryyy muchhhh @M。 Deinum ...你救了我的一天...非常感谢你... – user1755903

回答

0

您可以更改您的块代码:

<bean id="localeChangeInterceptor" 
     class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
      <property name="paramName" value="locale"></property> 
</bean> 

<bean id="localeResolver" 
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver"> 
    <property name="defaultLocale" value="kan"></property> 
</bean> 
<!-- the “order” property, where the lower order value has the higher priority. --> 
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> 
    <!--  <property name="order" value="1" /> --> 
    <property name="interceptors"> 
     <ref bean="localeChangeInterceptor"></ref> 
    </property> 
</bean> 

通过使用下面的代码:

​​