spring session使用jedis连接redis配置

19 篇文章 0 订阅

 

一、引入依赖

pom.xml

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-redis</artifactId>
    <version>1.7.10.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session</artifactId>
    <version>1.3.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9.0</version>
</dependency>

 

二、spring配置

spring-session.xml (名字任意)

<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
	<!-- 设置Session失效时间 -->
	<property name="maxInactiveIntervalInSeconds" value="1800"></property>
</bean>
       
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
	<property name="maxTotal" value="${redis.jedisPoolConfig.maxTotal}" />
	<property name="maxIdle" value="${redis.jedisPoolConfig.maxIdle}" />
	<property name="maxWaitMillis" value="${redis.jedisPoolConfig.maxWaitMillis}" />
	<property name="testOnBorrow" value="${redis.jedisPoolConfig.testOnBorrow}" />
	<property name="testOnReturn" value="${redis.jedisPoolConfig.testOnReturn}" />
</bean>

<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy">
	<property name="hostName" value="${redis.hostName}"/>
	<property name="port" value="${redis.port}"/>
	<property name="password" value="${redis.password}" />
	<property name="database" value="10" />
	<property name="timeout" value="60000"/>
	<property name="usePool" value="true"/>
	<property name="poolConfig" ref="jedisPoolConfig"/>
</bean>

 

redis.properties

redis.hostName=localhost
redis.password=password
redis.port=6379

redis.jedisPoolConfig.maxTotal=200
redis.jedisPoolConfig.maxIdle=50
redis.jedisPoolConfig.maxWaitMillis=60000
redis.jedisPoolConfig.testOnBorrow=true
redis.jedisPoolConfig.testOnReturn=true

 

三、配置filter

web.xml,(要引入spring-session.xml)

第一个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>
	<dispatcher>REQUEST</dispatcher>
	<dispatcher>ERROR</dispatcher>
</filter-mapping>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值