Spring Boot redis分散式session快速配置

帥氣你勇哥發表於2020-11-08

增加依賴

 <!--session-->
<dependency>
  <groupId>org.springframework.session</groupId>
  <artifactId>spring-session-data-redis</artifactId>
</dependency>
<!--redis-->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-redis</artifactId>
  <version>1.4.7.RELEASE</version>
</dependency>

配置redis

spring.redis.host=47.1.1.1
spring.redis.port=6379
spring.redis.password=11

開啟redissession開關且配置名稱空間

@ServletComponentScan
@SpringBootApplication
@EnableRedisHttpSession(redisNamespace="tianlun:pc")
public class TianlunpcApplication {
  public static void main(String[] args) {
    SpringApplication.run(TianlunpcApplication.class, args);
  }
}

相關文章