redis 安装
http://www.runoob.com/redis/redis-install.html
redis 参考
http://www.cnblogs.com/andyfengzp/p/6434287.html
增加
<!-- session redis依赖 start-->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<!-- session redis依赖 end -->
2.web.xml修改
在xml的前部位置(其他listner之前,加载配置文件之后)增加
<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>
3.jdbc.properties修改
增加
redis.hostname=127.0.0.1
redis.port=6379
redis.pwd=123456
4.spring-hibernate.xml修改
增加
<!-- redis的配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="100" />
<property name="maxIdle" value="10" />
</bean>
<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy">
<property name="hostName" value="${redis.hostname}"/>
<property name="port" value="${redis.port}"/>
<property name="password" value="${redis.pwd}" />
<property name="timeout" value="3000"/>
<property name="usePool" value="true"/>
<property name="poolConfig" ref="jedisPoolConfig"/>
</bean>
<!-- 为不同项目设置不同的cookie键值,避免产生host:端口部署不同项目产生覆盖cookie的问题 -->
<bean id="cookieSerializer" class="org.springframework.session.web.http.DefaultCookieSerializer" >
<property name="cookieName" value="修改成自己的项目名-cookie"></property>
</bean>
<bean id="redisHttpSessionConfiguration"
class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="1800"/>
<property name="redisNamespace" value="修改成自己的项目名"></property>
<property name="cookieSerializer" ref="cookieSerializer"></property>
</bean>
5.security.xml修改(如果不存在,这一步可以省略)
<bean id="sessionRegistry"
class="org.springframework.security.core.session.SessionRegistryImpl" />
修改为
<bean id="sessionRegistry" class="org.springframework.session.security.SpringSessionBackedSessionRegistry">
<constructor-arg name="sessionRepository" ref="sessionRepository"></constructor-arg>
</bean>
http://www.runoob.com/redis/redis-install.html
redis 参考
http://www.cnblogs.com/andyfengzp/p/6434287.html
http://dorole.com/1422/
http://blog.csdn.net/hdf734839030/article/details/52293275
增加
<!-- session redis依赖 start-->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<!-- session redis依赖 end -->
2.web.xml修改
在xml的前部位置(其他listner之前,加载配置文件之后)增加
<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>
3.jdbc.properties修改
增加
redis.hostname=127.0.0.1
redis.port=6379
redis.pwd=123456
4.spring-hibernate.xml修改
增加
<!-- redis的配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="100" />
<property name="maxIdle" value="10" />
</bean>
<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy">
<property name="hostName" value="${redis.hostname}"/>
<property name="port" value="${redis.port}"/>
<property name="password" value="${redis.pwd}" />
<property name="timeout" value="3000"/>
<property name="usePool" value="true"/>
<property name="poolConfig" ref="jedisPoolConfig"/>
</bean>
<!-- 为不同项目设置不同的cookie键值,避免产生host:端口部署不同项目产生覆盖cookie的问题 -->
<bean id="cookieSerializer" class="org.springframework.session.web.http.DefaultCookieSerializer" >
<property name="cookieName" value="修改成自己的项目名-cookie"></property>
</bean>
<bean id="redisHttpSessionConfiguration"
class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="1800"/>
<property name="redisNamespace" value="修改成自己的项目名"></property>
<property name="cookieSerializer" ref="cookieSerializer"></property>
</bean>
5.security.xml修改(如果不存在,这一步可以省略)
<bean id="sessionRegistry"
class="org.springframework.security.core.session.SessionRegistryImpl" />
修改为
<bean id="sessionRegistry" class="org.springframework.session.security.SpringSessionBackedSessionRegistry">
<constructor-arg name="sessionRepository" ref="sessionRepository"></constructor-arg>
</bean>