Spring session shared integration redis

 

 dependent jars

<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-data-redis</artifactId>
    <version>1.2.0.RELEASE</version>
</dependency>

spring configuration file

<!-- 将session放入redis -->
    <context:annotation-config/>
    <bean id="redisHttpSessionConfiguration"  class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration" >
        <property name="maxInactiveIntervalInSeconds" value="120" />
     </bean>
    <bean
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <!-- redis 配置 -->
        <property name="hostName" value="192.168.0.48" />
        <property name="port" value="6379" />
    </bean>

web.xml add filter

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-mvc.xml</param-value>
    </context-param>
    <!-- 分布式Session共享Filter -->
    <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>

 

1. This configuration file of spring must be written in the <context-param> section of web.xml, and cannot be written elsewhere.

2. The name of the filter must be springSessionRepositoryFilter

3. If shiro is used, <context-param> must be placed at the top of web.xml, then write the filter configuration of shiro, and then write the filter configuration of spring-session. The rest of the encoding and servlet configuration follows.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326680124&siteId=291194637