springboot分布式session同步

来源:互联网 发布:天翼飞young客户端mac 编辑:程序博客网 时间:2024/06/07 12:14

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配置:

@Configurationpublic 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: 

原创粉丝点击