编写如下配置类即可(因为我们登录是在认证服务模块,而登录后跳转到首页是在商品服务模块,并且我们修改了session的名字,为了两个服务都可以取到该session,我们将该配置类在两个服务中都放了一份)
package com.gulimall.authserver.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;
/**
* SpringSession的自定义配置
* 1、修改session的作用域(放大)
* 2、修改存储到redis的序列化机制(以json方式存储)
*/
@Configuration
public class GulimallSessionConfig{
@Bean
public CookieSerializer cookieSerializer(){
DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
cookieSerializer.setDomainName("gulimall.com");//修改session的作用域
cookieSerializer.setCookieName("GULIMALLSESSION");//修改cookie的名字
return cookieSerializer;
}
//修改存储到redis中的数据的序列化机制
@Bean
public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
return new GenericJackson2JsonRedisSerializer();
}
}
标签:cookieSerializer,自定义,子域,springframework,---,session,import,org
From: https://www.cnblogs.com/morehair/p/17113900.html