zoukankan      html  css  js  c++  java
  • spring-session-redis的配置

    1.pom.xml的配置

             <dependency>  

                <groupId>org.springframework.session</groupId>  

               <artifactId>spring-session-data-redis</artifactId>  

               <version>1.0.2.RELEASE</version>  

        </dependency>

     

    1.配置web.xml,配置拦截器,加载springmvc

    <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>

    2.配置spring-mvc.xml,配置redis的地址

    <bean id="jedisConnectionFactory"
    class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
    <property name="hostName" value="localhost"/>
    <property name="port" value="6379"/>
    </bean>

    <!-- redis template definition -->
    <bean id="redisTemplate"
    class="org.springframework.data.redis.core.RedisTemplate">
    <property name="connectionFactory" ref="jedisConnectionFactory"/>
    <property name="keySerializer" ref="stringRedisSerializer" />
    <property name="hashKeySerializer" ref="stringRedisSerializer" />
    <property name="valueSerializer" ref="stringRedisSerializer" />
    </bean>

    <!-- session redis cache config -->
    <bean id="redisHttpSessionConfiguration"
    class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
      <property name="maxInactiveIntervalInSeconds" value="6000"></property> <!--单位秒-->
    </bean>

    通过以上配置,session就能自动存在redis中了。

     

     

  • 相关阅读:
    Static Fields and Methods
    usermod
    理解Java的Class类、"this."关键字、Constructor构造器(一)
    [REPRINT] Java 101: Classes and objects in Java
    第六章 Java并发容器和框架
    第五章 Java中锁
    第四章 Java并发编程基础
    第三章 Java内存模型(下)
    第三章 Java内存模型(上)
    第二章 并发机制的底层实现原理
  • 原文地址:https://www.cnblogs.com/chenshijun007/p/7365461.html
Copyright © 2011-2022 走看看