Springboot springsession Redis Shared SESSION

Source: Internet
Author: User
Tags set time redis server

Known as seamless integration httpsession sharing,

Note, however, that if there is a third-party framework, such as session concurrency control, it is necessary to rewrite the session list yourself.

POM

    <!--Redis -        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-data-redis</Artifactid>            <version>1.5.4.RELEASE</version>        </Dependency>        <!--Redis Session -        <Dependency>            <groupId>Org.springframework.session</groupId>            <Artifactid>Spring-session-data-redis</Artifactid>            <version>1.3.1.RELEASE</version>        </Dependency>
Redissessionconfig
/***/@Configuration//maxinactiveintervalinseconds Session time-out, unit seconds @EnableRedisHttpSession (maxinactiveintervalinseconds =)publicclass  Redissessionconfig {}
Rediscacheconfig
 Packagecom.lzw.core.configuration;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;ImportOrg.springframework.beans.factory.annotation.Value;ImportOrg.springframework.cache.CacheManager;ImportOrg.springframework.cache.annotation.CachingConfigurerSupport;Importorg.springframework.cache.annotation.EnableCaching;ImportOrg.springframework.context.annotation.Bean;Importorg.springframework.context.annotation.Configuration;ImportOrg.springframework.data.redis.cache.RedisCacheManager;Importorg.springframework.data.redis.connection.RedisConnectionFactory;Importorg.springframework.data.redis.core.RedisTemplate;ImportRedis.clients.jedis.JedisPool;ImportRedis.clients.jedis.JedisPoolConfig;ImportJava.util.Map;ImportJava.util.concurrent.ConcurrentHashMap;/*** Created by Zhenweilai on 2017/6/11.*/@Configuration @enablecaching Public classRediscacheconfigextendscachingconfigurersupport {Logger Logger= Loggerfactory.getlogger (rediscacheconfig.class); @Value ("${spring.redis.host}")    PrivateString host; @Value ("${spring.redis.port}")    Private intPort; @Value ("${spring.redis.timeout}")    Private inttimeout; @Value ("${spring.redis.pool.max-idle}")    Private intMaxidle; @Value ("${spring.redis.pool.max-wait}")    Private LongMaxwaitmillis; @Value ("${spring.redis.password}")    PrivateString password; @Bean PublicJedispool redispoolfactory () {Logger.info ("Jedispool Injection success!! "); Jedispoolconfig Jedispoolconfig=NewJedispoolconfig ();        Jedispoolconfig.setmaxidle (Maxidle);        Jedispoolconfig.setmaxwaitmillis (Maxwaitmillis); Jedispool Jedispool=NewJedispool (Jedispoolconfig, host, port, timeout, password); returnJedispool; } @Bean PublicRedistemplate<string, string>redistemplate (Redisconnectionfactory CF) {redistemplate<string, string> redistemplate =NewRedistemplate<string, string>();        Redistemplate.setconnectionfactory (CF); returnredistemplate; } @Bean PublicCacheManager CacheManager (redistemplate redistemplate) {Rediscachemanager CacheManager=NewRediscachemanager (redistemplate); //default time-out, per secondCachemanager.setdefaultexpiration (3000); //set time-out based on cache name, 0 not timed outMap<string,long> expires =NewConcurrenthashmap<>();        Cachemanager.setexpires (expires); returnCacheManager; }}

Application.yml

spring:datasource:# readsize:1# name:writedatasource type:com.alibaba.druid.pool.DruidDataSource writ E:driver-class-name:com.mysql.jdbc.driver url:jdbc:mysql://localhost:3306/cloud?useunicode=true&characterencoding=utf-8&zerodatetimebehavior=converttonull&transformedbitisboolean=true&usessl=true username:root password:123 initialsize:10 maxactive:100 maxwait:60000 minidle      : 5 timebetweenevictionrunsmillis:60000 minevictableidletimemillis:300000 validationquery:select ' x ' Testwhileidle:true testonborrow:false testonreturn:false poolpreparedstatements:true maxPoolPrep  Aredstatementperconnectionsize:20 #redis配置 redis:host:192.168.1.11 port:6379 # Redis (redisproperties) # Redis Database Index (default = 0) database:0 # Redis Server connection password (default is empty) Password: # Connection pool Max connections (with negative value for no limit) # Connection time-out (milliseconds) timeout      : 0 Pool:max-active:8 # Connection pool maximum blocking wait time (with negative value for No limit) max-wait: 1 # Maximum idle connection in the connection pool Max-idle:8 # The minimum idle connection in the connection pool min-idle:0

Springboot springsession Redis Shared SESSION

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.