2016-09-07 106 views
0

我使用spring session HttpSession,我该如何定制cookie关键字,我试过这个解决方案:Custom cookie name when using Spring Session。但它不起作用,名字仍然是SESSION。java spring session如何自定义cookie关键字

我的配置如下图所示:

<context:annotation-config/> 
<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"/> 
<context:property-placeholder location="classpath:/env/env_test.properties"/> 
<bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" 
    p:port="${spring.redis.port}" p:hostName="${spring.redis.host}"/> 
<bean id="mapSessionRepository" class="org.springframework.session.MapSessionRepository" /> 
<bean id="sessionRepositoryFilter"    
    class="org.springframework.session.web.http.SessionRepositoryFilter"> 
    <constructor-arg ref="sessionRepository"/> 
    <property name="httpSessionStrategy"> 
    <bean class="org.springframework.session.web.http.CookieHttpSessionStrategy"> 
     <property name="cookieName" value="_session_id" /> 
    </bean> 
    </property> 
</bean> 

回答

0

你只需要添加下面bean创建custom cookie

<bean class ="org.springframework.session.web.http.DefaultCookieSerializer"> 
      <property name="cookieName" value="JSESIONID"></property>  
    </bean> 

JESSIONID - Custom Cookie Name 

    Please remove below configuration fr`enter code here`om xml file. 

    <bean id="sessionRepositoryFilter"    
     class="org.springframework.session.web.http.SessionRepositoryFilter"> 
     <constructor-arg ref="sessionRepository"/> 
     <property name="httpSessionStrategy"> 
     <bean class="org.springframework.session.web.http.CookieHttpSessionStrategy"> 
      <property name="cookieName" value="_session_id" /> 
     </bean> 
     </property> 
    </bean>