目录
session共享原理
分布式下session共享问题
分布式下session共享问题解决方案
session复制
客户端存储
hash一致性
统一存储
整合SpringSession
引入SpringSession
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
配置SpringSession
spring.session.store-type=redis
@Configuration
@EnableRedisHttpSession
public class SessionConfig {
@Value("${idea.domain}")
private String ideaDomain;
@Bean
public CookieSerializer cookieSerializer() {
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
serializer.setDomainName(ideaDomain);
serializer.setCookieName("JSESSIONID");
return serializer;
}
@Bean
public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
return new GenericJackson2JsonRedisSerializer();
}
}
SpringSession原理(装饰者模式)
- SessionRepositoryFilter