spring配置redis

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">


<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="300"/> <!-- 控制一个pool可分配多少个jedis实例 -->
<property name="maxIdle" value="100" /> <!-- 控制一个pool最多有多少个状态为idle(空闲)的jedis实例 -->
<property name="maxWaitMillis" value="2000" /> <!-- 表示当borrow一个jedis实例时,最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException -->
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
</bean>
<!-- redis的连接池pool,不是必选项:timeout/password -->
<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.host}" />
<property name="port" value="${redis.port}" />
<property name="password" value="${redis.passWord}" />
<property name="poolConfig" ref="jedisPoolConfig" />
</bean>


<bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory">
<ref bean="jedisConnectionFactory" />
</property>
</bean>
<!-- 配置springRedis -->
<bean id="springRedis" class="com.inborn.inshop.common.redis.SpringRedis">
<property name="redisKeyPrefix" value="${redis.key.prefix}" />
<property name="stringRedisTemplate">
<ref bean="stringRedisTemplate" />
</property>
</bean>

</beans>

原文地址:https://www.cnblogs.com/lvgg/p/6655359.html