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中了。

     

     

  • 相关阅读:
    D. Beautiful Array
    C. Magic Ship Educational Codeforces Round 60 (Rated for Div. 2)
    CCPC-Wannafly Winter Camp Day3 小清新数论(莫比乌斯反演反演加杜教筛)
    杜教筛
    Algorithms Weekly 3
    Algorithms Weekly 2
    Algorithms Weekly 1
    KNN算法实现数字识别
    2019总结
    2019 Google Kickstart Round H
  • 原文地址:https://www.cnblogs.com/chenshijun007/p/7365461.html
Copyright © 2011-2022 走看看