spring boot 使用 redis session

2 using spring boot redis

Use redis sharing session

Distributed systems, Session shared a lot of solutions, which hosted the cache should be one of the most common scenario

  1. pom dependent file introduced

    <!-- redis -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
    <!-- security -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <!-- redis session -->
    <dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-data-redis</artifactId>
    </dependency>

spring session in default added security without adding security will depend Throws:
java.lang.ClassNotFoundException: org.springframework.security.web.authentication.RememberMeServices

2.redis Configuration

#redis配置
#Redis服务器地址
spring.redis.host=192.168.5.10
#Redis服务器连接端口
spring.redis.port=6379
#Redis数据库索引(默认为0)
spring.redis.database=4
#连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=50
#连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=3000
#连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=20
#连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=2
#连接超时时间(毫秒)
spring.redis.timeout=5000

spring.session.store-type=redis

3. Turn redis session at startup class

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@MapperScan("com.example.demo.dao.mybatis")
@EnableCaching
@EnableRedisHttpSession
public class DemoApplication 

@SpringBootApplication (exclude = {SecurityAutoConfiguration.class}) to remove the security certification authority automatic assembly
removed not to cause insufficient privileges

----end----

Guess you like

Origin blog.51cto.com/5013162/2404433