1.pom.xml 依赖
<!-- spring session -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<!-- redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
2.配置属性
#spring session使用存储类型
spring.session.store-type=redis
#spring session刷新模式:默认on-save
spring.session.redis.flush-mode=on-save
spring.session.redis.namespace=
#session超时时间,单位秒
server.session.timeout=30
#redis
spring.redis.host=localhost
spring.redis.port=6379
spring.redis.password=123456
spring.redis.database=0
spring.redis.pool.max-active=8
spring.redis.pool.max-idle=8
spring.redis.pool.max-wait=-1
spring.redis.pool.min-idle=0
spring.redis.timeout=0
3.测试
@RequestMapping(value = "/index")
public String index(ModelMap map, HttpSession httpSession) {
map.put("title", "第一个应用:sessionID=" + httpSession.getId());
System.out.println("sessionID=" + httpSession.getId());
return "index";
}