1: Add Jar Package
<Dependency> <groupId>Org.springframework.data</groupId> <Artifactid>Spring-data-redis</Artifactid> <version>2.0.3.RELEASE</version> </Dependency> <Dependency> <groupId>Redis.clients</groupId> <Artifactid>Jedis</Artifactid> <version>2.9.0</version> </Dependency> <Dependency> <groupId>Org.springframework.session</groupId> <Artifactid>Spring-session-data-redis</Artifactid> <version>2.0.1.RELEASE</version> </Dependency> <Dependency> <groupId>Org.apache.commons</groupId> <Artifactid>Commons-pool2</Artifactid> <version>2.4.2</version> </Dependency>
2: Compounding
<BeanID= "Jedispoolconfig"class= "Redis.clients.jedis.JedisPoolConfig"> < Propertyname= "Maxtotal"value= "${utils.redis.maxtotal}" /> < Propertyname= "Maxidle"value= "${utils.redis.maxidle}" /> < Propertyname= "Timebetweenevictionrunsmillis"value= "${utils.redis.timebetweenevictionrunsmillis}" /> < Propertyname= "Minevictableidletimemillis"value= "${utils.redis.minevictableidletimemillis}" /> < Propertyname= "Testonborrow"value= "${utils.redis.testonborrow}" /> </Bean> <BeanID= "Jedisconnfactory"class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> < Propertyname= "HostName"value= "${utils.redis.host}" /> < Propertyname= "Port"value= "${utils.redis.port}" /> < Propertyname= "Password"value= "${utils.redis.pass}" /> < Propertyname= "Database"value= "${utils.redis.database}" /> < Propertyname= "Timeout"value= "${utils.redis.timeout}" /> < Propertyname= "Poolconfig"ref= "Jedispoolconfig" /> < Propertyname= "Usepool"value= "true" /> </Bean>
<!--remove config--> from Redis client<util:constantStatic-field= "Org.springframework.session.data.redis.config.ConfigureRedisAction.NO_OP"/> <Beanclass= "Org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"> < Propertyname= "Maxinactiveintervalinseconds"value= "3600" /> </Bean>
3: The filter of the XML, it is best to put the filter first bit
<Filter> <Filter-name>Springsessionrepositoryfilter</Filter-name> <Filter-class>Org.springframework.web.filter.DelegatingFilterProxy</Filter-class> </Filter> <filter-mapping> <Filter-name>Springsessionrepositoryfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping>
Summary: As simple as this, the session can be used normally
Spring-session-data-redis using Redis shared session