Spring localechangeinterceptor not working

2019-06-05 09:01发布

问题:

I searched many topics but I couldnt find a solution.My internalization works when i set defaultlocale in spring-servlet.xml, but I cannot change locale when i clicked link and set new locale. English

My xml is below ;

<?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>