1, Pom
<modelVersion>4.0.0</modelVersion> <groupId>com.x.redis</groupId> <artifactId> springredis</artifactid> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency& Gt <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.0.2.RELEASE</version> </dependency> <dependency> <groupid& Gt;org.springframework</groupid> <artifactId>spring-test</artifactId> <version>3 .1.2.release</version> <scope>test</scope> </dependency> <DEPENDENCY&G T <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2 .1.0</version> </dependency> <dependency> <groupId>junit</groupId> ≪artifactid>junit</artifactid> <version>4.8.2</version> <scope>test</sco Pe> </dependency> </dependencies>
2, Spring configuration file (applicationcontext.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:p= "http://www.springframework.org/schema/p" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:jee= "Http://www.springframework.org/schema/jee" xmlns:tx= " Http://www.springframework.org/schema/tx "xmlns:aop=" HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP "xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context.xsd "><context:property-placeholder location=" classpath:redis.properties "/><bean id=" Poolconfig "class=" Redis.clients.jedis.JedisPoolConfig "><property name=" Maxidle "value=" ${redis.maxidle} "/ ><property name= "maxactive" value= "${redis.maxactive}"/><property name= "maxWait" value= "${ redis.maxwait} "/><propErty name= "Testonborrow" value= "${redis.testonborrow}"/></bean><bean id= "connectionFactory" class= " Org.springframework.data.redis.connection.jedis.JedisConnectionFactory "P:host-name=" ${redis.host} "p:port=" ${ Redis.port} "p:password=" ${redis.pass} "p:pool-config-ref=" Poolconfig "/><bean id=" redisTemplate "class=" Org.springframework.data.redis.core.RedisTemplate "><property name=" ConnectionFactory "ref=" ConnectionFactory "/></bean><bean id=" Userdao "class=" Com.x.dao.impl.userdao "/> </beans>//Another <bean id= "jedisPool0" class= "Redis.clients.jedis.JedisPool" > <constructor-arg name= "poolconfig" ref= "Jedis Poolconfig "/> <constructor-arg name=" host "value=" ${redis.ip} "type=" Java.lang.String "/> <constr Uctor-arg name= "Port" value= "${redis.port}" type= "int"/> <constructor-arg name= "Timeout" value= "$" type= "I NT "/> <constructor-arg name=" password "value=" ${redis.password} "/><constructor-arg name= "Database" value= "0" type= "int"/> </bean>
3, Redis.properties
# Redis Settings redis.host=localhost redis.port=6379 redis.pass=java2000_wl redis.maxidle=300 redis.maxactive=600 redis.maxwait=1000 redis.testonborrow=true
Redis + Spring Integration