spring-session-data-redis使用redis共享session

1:添加jar包

<dependency>
            <groupId>org.springframework.datagroupId>
            <artifactId>spring-data-redisartifactId>
            <version>2.0.3.RELEASEversion>
        dependency>
        <dependency>
            <groupId>redis.clientsgroupId>
            <artifactId>jedisartifactId>
            <version>2.9.0version>
        dependency>
        <dependency>
            <groupId>org.springframework.sessiongroupId>
            <artifactId>spring-session-data-redisartifactId>
            <version>2.0.1.RELEASEversion>
        dependency>
        <dependency>
            <groupId>org.apache.commonsgroupId>
            <artifactId>commons-pool2artifactId>
            <version>2.4.2version>
        dependency>

2:配制

  

    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxTotal" value="${utils.redis.maxTotal}" />
        <property name="maxIdle" value="${utils.redis.maxIdle}" />
        <property name="timeBetweenEvictionRunsMillis" value="${utils.redis.timeBetweenEvictionRunsMillis}" />
        <property name="minEvictableIdleTimeMillis" value="${utils.redis.minEvictableIdleTimeMillis}" />
        <property name="testOnBorrow" value="${utils.redis.testOnBorrow}" />
    bean>


    <bean id="jedisConnFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="hostName" value="${utils.redis.host}" />
        <property name="port" value="${utils.redis.port}" />
        <property name="password" value="${utils.redis.pass}" />
        <property name="database" value="${utils.redis.database}" />
        <property name="timeout" value="${utils.redis.timeout}" />
        <property name="poolConfig" ref="jedisPoolConfig" />
        <property name="usePool" value="true" />
    bean>

<util:constant static-field="org.springframework.session.data.redis.config.ConfigureRedisAction.NO_OP"/> <bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"> <property name="maxInactiveIntervalInSeconds" value="3600" /> bean>

3:配制xml的filter,最好放filter第一位

    <filter>
        <filter-name>springSessionRepositoryFilterfilter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxyfilter-class>
    filter>
    <filter-mapping>
        <filter-name>springSessionRepositoryFilterfilter-name>
        <url-pattern>/*url-pattern>
    filter-mapping>

 

总结:就这么简单,session可以正常使用了

 

转载于:https://www.cnblogs.com/feiyun126/p/8431325.html

你可能感兴趣的:(数据库,java)