The project uses is Springmvc+hibernate, listens to eldest brother's opinion uses spring-session to carry on the processing session, uses Redis managed session. Below is a formal record of the processing method.
1. If the project did not integrate Spring-data-redis before, this step needs to be done first, add these dependencies in Maven:
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId> spring-session-data-redis</artifactid>
<version>1.0.1.RELEASE</version>
</ dependency>
<dependency>
<groupId>org.springframework.session</groupId>
< artifactid>spring-session</artifactid>
<version>1.0.1.RELEASE</version>
</ dependency>
<dependency>
<groupId>com.orange.redis-embedded</groupId>
< artifactid>embedded-redis</artifactid>
<version>0.6</version>
</dependency >
2. Add the following bean to the applicationcontext.xml to define the Redis connection pool and initialize the Redis template operation class to replace the related variables.
<!--Redis--> <bean id= "Jedispoolconfig" class= "Redis.clients.jedis.JedisPoolConfig" > </bean> < Bean id= "jedisconnectionfactory" class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
> <property name= "hostName" value= "${redis.host}"/> <property name= "port" value= "${redis.port}"/> <property name= "Password" value= "${redis.pass}"/> <property name= "Timeout" value= "${redis.timeout}"/&G
T <property name= "Poolconfig" ref= "Jedispoolconfig"/> <property name= "Usepool" value= "true"/>
; <bean id= "Redistemplate" class= "org.springframework.data.redis.core.StringRedisTemplate" > <property name= "ConnectionFactory" ref= "Jedisconnectionfactory"/> </bean> <!--put session into Redis--> <bean " Redishttpsessionconfiguration "Class=" Org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration "> < PropertyName= "Maxinactiveintervalinseconds" value= "1800"/> </bean>
3. Then add a session agent filter in the Web.xml to wrap the getsession () of the servlet through this filter. Put the configuration to the front, giving it the highest priority.
<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>
#------------Redis------------
redis.host=192.168.1.174
redis.port=6379
redis.pass=
redis.timeout=1800
Then there are all sorts of treatments, request.getSession.setAttribute, etc.
Test Link:
1. Open two tomcat,eg:localhost:8888 and localhot:8080 and then run them.
2. Open a browser (be sure to use the same browser), open a tab of 8080, and then log in, into the personal center (need to login to enter the interface). Once logged in, the connection is copied to another browser tab, the port is changed to 8888, and you are logged in without logging in.
3. View Redis,mac can use the RDM tool
From: http://my.oschina.net/piaofudeyu/blog/552402