Spring localechangeinterceptor无法正常工作

时间:2015-10-07 11:43:24

标签: spring internationalization locale

我搜索了很多主题,但我找不到解决方案。当我在spring-servlet.xml中设置defaultlocale时,我的内部化工作正常,但是当我点击链接并设置新的语言环境时,我无法更改语言环境。 英

我的xml在下面;

<?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:c="http://www.springframework.org/schema/c"
	xmlns:cache="http://www.springframework.org/schema/cache"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
	
	<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/WEB-INF/view/"
		p:suffix=".jsp"  />
	
	
	<bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource"
        p:basename="language.messages"
        p:useCodeAsDefaultMessage="true"/>
	
	<mvc:interceptors>
	    <mvc:interceptor>
	        <mvc:mapping path="/**" />
	        <bean id="localeChangeInterceptor"
	            class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
	            <property name="paramName" value="language" />
	        </bean>
	    </mvc:interceptor>
	</mvc:interceptors>
	
	<bean id="localeResolver"
	    class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
	    <property name="cookieName" value="language" />
	    <property name="defaultLocale" value="tr" />
	</bean>
	 	
	 
	
	<!-- Configure the multipart resolver -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="5097152" />
    </bean>
    
	<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">      
		<property name="order" value="1" />      
		<property name="mediaTypes">        
			<map>           
			  <entry key="json" value="application/json" />           
			  <entry key="xml" value="application/xml" />           
			  <entry key="pdf" value="application/pdf" /> 
			  <entry key="xlsx" value="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />        
			</map>      
		</property>       
		
		<property name="defaultViews">        
			<list>          
				<!-- JSON View -->          
				<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" p:prettyPrint="true" >          
				</bean>          
				
				<!--  XML view -->            
				<bean class="org.springframework.web.servlet.view.xml.MarshallingView">            
				<constructor-arg>                
					<bean class="org.springframework.oxm.castor.CastorMarshaller">                   
						          
					</bean>            
				</constructor-arg>          
				</bean>          
				
				<!--  PDF view -->          
				<bean class="com.sni.spring.view.PDFView">             
				</bean>
				
				<!--  XLSX "Excel" view -->          
				<bean class="com.sni.spring.view.ExcelView">             
				</bean>
			</list>      
		</property>      
		
		<property name="ignoreAcceptHeader" value="true" />     
	</bean>
	
		
</beans>

0 个答案:

没有答案