zoukankan      html  css  js  c++  java
  • Spring session共享问题 将session放入redis(转)

    将session放入放入redis缓存中可以解决多个应用session共享问题

    一、主要pom依赖

         
    <dependency>
          <groupId>org.springframework.session</groupId>
          <artifactId>spring-session-data-redis</artifactId>
          <version>1.2.1.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>redis.clients</groupId>
          <artifactId>jedis</artifactId>
          <version>2.8.1</version>
        </dependency>

    二、spring配置

     
     <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
            <property name="maxTotal" value="30"/>
            <property name="maxIdle" value="10"/>
            <property name="minIdle" value="1"/>
            <property name="maxWaitMillis" value="30000"/>
            <property name="testOnBorrow" value="true"/>
            <property name="testOnReturn" value="false"/>
            <property name="testWhileIdle" value="false"/>
        </bean>
    
        <context:annotation-config/>
        <!-- 把session放入redis -->
        <bean id="redisHttpSessionConfiguration"
              class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
            <property name="maxInactiveIntervalInSeconds" value="1800"/>
        </bean>
    
        <!-- redis连接池 -->
        <bean id="jedisConnectionFactory"
              class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy">
            <property name="hostName" value="127.0.0.1"/>
            <property name="port" value="6379"/>
           <property name="password" value="yourpass" /> 
            <property name="timeout" value="3000"/>
            <property name="usePool" value="true"/>
            <property name="poolConfig" ref="jedisPoolConfig"/>
        </bean>
    
        <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
            <property name="connectionFactory" ref="jedisConnectionFactory"/>
        </bean>

    三、web.xml配置fiter和session生命周期

      <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>
    
      <session-config>
        <session-timeout>30</session-timeout>
      </session-config>

    四、使用及验证结果

    直接使用 request.getSession().setAttribute("springtest","test"); 就把session放入缓存中了
    在redis中查看key
     
    原文   http://blog.csdn.net/u012515742/article/details/54973075
  • 相关阅读:
    Generative Adversarial Nets
    【 剑指Offer 1 】数据结构
    Hopfield神经网络
    LSTMs 长短期记忆网络系列
    【 记忆网络 2 】 End-to-End Memory Network
    MessagePack Java Jackson Dataformat
    MessagePack Java 0.6.X 动态类型
    MessagePack Java 0.6.X 可选字段
    MessagePack Java 0.6.X 不使用注解(annotations)来序列化
    MessagePack Java 0.6.X List, Map 对象的序列化和反序列化
  • 原文地址:https://www.cnblogs.com/ltian123/p/13364809.html
Copyright © 2011-2022 走看看