Spring Session - HttpSession

1.添加依赖


    org.springframework.session
    spring-session-data-redis
    2.0.6.RELEASE
    pom


    io.lettuce
    lettuce-core
    5.0.5.RELEASE


    org.springframework
    spring-web
    5.0.9.RELEASE


2.配置session Config,添加带有如下注解的类
@EnableRedisHttpSession
public class Config {

@Bean
public LettuceConnectionFactory connectionFactory() {
    return new LettuceConnectionFactory(new RedisStandaloneConfiguration("localhost", 6379)); 
}

}
** Redis 的配置,参考Spring Data Redis
https://docs.spring.io/spring-data/data-redis/docs/2.0.10.RELEASE/reference/html

3.添加session配置到servlet 容器
public class Initializer extends AbstractHttpSessionApplicationInitializer {

public Initializer() {
    super(Config.class); 
}

}

你可能感兴趣的:(Spring Session - HttpSession)