springboot分佈式session同步

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: 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章