spring xml配置
<?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:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.2.xsd "> <cache:annotation-driven /> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}" /> <property name="maxWaitMillis" value="${redis.maxWait}" /> <property name="testOnBorrow" value="${redis.testOnBorrow}" /> </bean> <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <property name="poolConfig" ref="poolConfig" /> <property name="port" value="${redis.master.port}" /> <property name="hostName" value="${redis.master.host}" /> <property name="password" value="${redis.master.password}" /> <property name="database" value="${redis.default.db}"></property> </bean> <bean id="redisConnectionTimeoutAspect" class="com.paic.p2pp_ir.common.RedisConnectionTimeoutAspect" /> <aop:config proxy-target-class="true" > <!-- 以类的方式申明代理,因为redisTemplate是一个类 --> <aop:aspect ref="redisConnectionTimeoutAspect" > <aop:pointcut id="redisPointCut" expression="execution(public * org.springframework.data.redis.core.RedisTemplate.execute(..))" /> <aop:around method="around" pointcut-ref="redisPointCut"/> </aop:aspect> </aop:config> <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="connectionFactory" /> <property name="keySerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" /> </property> <property name="valueSerializer"> <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" /> </property> </bean> <bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager"> <constructor-arg ref="redisTemplate" /> <property name="defaultExpiration" value="1800"/> <property name="cacheNames"> <bean class="java.util.ArrayList"> <constructor-arg index="0"> <list> <value>ir_cache</value> </list> </constructor-arg> </bean> </property> </bean> </beans>