maven:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!-- Spring-boot session manager --> <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> </dependency>redis配置:
@Configuration public class SpringConfig { @Autowired Environment env; @Bean public JedisPoolConfig jedisPoolConfig() { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxIdle(env.getProperty("redis.pool.config.maxidle", Integer.class, 8)); poolConfig.setMaxTotal(env.getProperty("redis.pool.config.maxtotal", Integer.class, 8)); return poolConfig; } @Bean public JedisPool jedisPool(JedisPoolConfig jedisPoolConfig) { return new JedisPool(jedisPoolConfig, env.getProperty("redis.pool.host", Protocol.DEFAULT_HOST), env.getProperty("redis.pool.port", Integer.class, Protocol.DEFAULT_PORT), env.getProperty("redis.pool.timeout", Integer.class, Protocol.DEFAULT_TIMEOUT), env.getProperty("redis.pool.password", (String) null)); } }启动main
@SpringBootApplication @EnableRedisHttpSession(maxInactiveIntervalInSeconds = 24 * 60 * 60) @ImportResource({"classpath:META-INF/spring/dubbo-consumer.xml"}) public class Bootstrap { public static void main(String[] args) { SpringApplication.run(Bootstrap.class, args); } }application.yml
redis: pool: host: port: timeout: password: config: maxtotal: maxidle: spring: session: store-type : redis redis: host: port: password: