导包
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
</dependencies>
配置yml文件
spring:
session:
store-type: redis
timeout: 3600s
redis:
flush-mode: on_save
namespace: spring:session
redis:
# 此处是你的ip
host: redis
port: 6379
timeout: 5000ms
启动类上
package com.zhk.study;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
@SpringBootApplication
@EnableRedisHttpSession
public class StudyApplication {
public static void main(String[] args) {
SpringApplication.run(StudyApplication.class,args);
}
}