spring-context-jedis.xml 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="
  4. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  5. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"
  6. default-lazy-init="true">
  7. <description>Jedis Configuration</description>
  8. <!-- 加载配置属性文件 -->
  9. <context:property-placeholder ignore-unresolvable="true" location="classpath:caimei.properties" />
  10. <!-- spring data redis -->
  11. <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
  12. <property name="usePool" value="true"></property>
  13. <property name="hostName" value="${redis.host}" />
  14. <property name="port" value="${redis.port}" />
  15. <property name="password" value="#{'${redis.pass}'!='123456'?'${redis.pass}':null}" />
  16. <property name="timeout" value="${redis.timeout}" />
  17. <property name="database" value="0"></property>
  18. <constructor-arg index="0" ref="jedisPoolConfig" />
  19. </bean>
  20. <!-- jedis pool配置 -->
  21. <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
  22. <property name="maxTotal" value="${redis.pool.maxTotal}"/>
  23. <property name="maxIdle" value="${redis.pool.maxIdle}"/>
  24. <property name="minIdle" value="${redis.pool.minIdle}"/>
  25. <property name="maxWaitMillis" value="${redis.pool.maxWait}"/>
  26. <property name="testOnBorrow" value="true"/>
  27. <property name="testOnReturn" value="false"/>
  28. <property name="testWhileIdle" value="false"/>
  29. <!-- <property name="testOnBorrow" value="${redis.testOnBorrow}" /> -->
  30. </bean>
  31. <!-- Redis Template -->
  32. <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
  33. <property name="connectionFactory" ref="jedisConnectionFactory" />
  34. <property name="keySerializer">
  35. <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
  36. </property>
  37. <property name="hashKeySerializer">
  38. <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
  39. </property>
  40. <property name="valueSerializer">
  41. <bean class="com.caimei.redis.GenericJackson2JsonRedisSerializer"/>
  42. </property>
  43. <property name="hashValueSerializer">
  44. <bean class="com.caimei.redis.GenericJackson2JsonRedisSerializer"/>
  45. </property>
  46. </bean>
  47. <!--<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
  48. <property name="maxActive" value="${redis.pool.maxActive}" />&lt;!&ndash;最大连接数&ndash;&gt;
  49. <property name="maxIdle" value="${redis.pool.maxIdle}" /> &lt;!&ndash;最大空闲连接数,即 最大能够保持idel状态的对象数 &ndash;&gt;
  50. <property name="minIdle" value="${redis.pool.minIdle}"/>&lt;!&ndash;初始化连接数&ndash;&gt;
  51. <property name="maxWait" value="${redis.pool.maxWait}" /> &lt;!&ndash;最大等待时间&ndash;&gt;
  52. <property name="maxTotal" value="${redis.pool.maxTotal}" /> &lt;!&ndash; 最大分配的对象数 &ndash;&gt;
  53. <property name="testOnBorrow" value="true" /> &lt;!&ndash; 当调用borrow Object方法时,是否进行有效性检查 &ndash;&gt;
  54. </bean>
  55. <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
  56. <constructor-arg index="0" ref="jedisPoolConfig" />
  57. <constructor-arg index="1" value="${redis.host}" />
  58. <constructor-arg index="2" value="${redis.port}" type="int" />
  59. &lt;!&ndash;timeout&ndash;&gt;
  60. <constructor-arg index="3" value="${redis.timeout}"/>
  61. <constructor-arg index="4" value="${${redis.password}}"/>
  62. </bean>-->
  63. </beans>