spring-config-one-redis.xml 3.2 KB
<?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:p="http://www.springframework.org/schema/p"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  
  
    <context:component-scan base-package="com.sibu.orderHelper.common.redis" annotation-config="true" />
  
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">  
        <property name="maxIdle" value="10"/>
        <property name="minIdle" value="2"/>
        <property name="minEvictableIdleTimeMillis" value="300000"/>
        <property name="numTestsPerEvictionRun" value="3"/>
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>
        <property name="testOnBorrow" value="true"/>
        <property name="testOnReturn" value="true"/>
        <property name="testWhileIdle" value="true"/>
    </bean>  
  
    <bean id="jedisConnectionFactory"  
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"  
        destroy-method="destroy">  
        <property name="hostName" value="${redis.host}" />  
        <property name="port" value="${redis.port}" />  
        <property name="timeout" value="${redis.timeout}" />  
        <property name="database" value="${redis.database}" />  
        <property name="password" value="${redis.password}" /> 
        <property name="usePool" value="${redis.usePool}" />  
        <property name="poolConfig" ref="jedisPoolConfig" />  
    </bean>
    
    <!-- redis template definition p表示对该bean里面的属性进行注入,格式为p:属性名=注入的对象 效果与在bean里面应用<property>标签一样 -->  
    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
        p:connection-factory-ref="jedisConnectionFactory">
        <!-- 序列化方式 建议key/hashKey采用StringRedisSerializer。 -->  
        <property name="keySerializer">  
            <bean
                class="org.springframework.data.redis.serializer.StringRedisSerializer" />  
        </property>  
        <property name="hashKeySerializer">  
            <bean
                class="org.springframework.data.redis.serializer.StringRedisSerializer" />  
        </property>  
        <property name="valueSerializer">  
            <bean
                class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />  
        </property>  
        <property name="hashValueSerializer">
            <bean  
                class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />  
        </property>  
    </bean>
    
    <!-- redis服务封装 -->  
	<bean id="redisDaoTool" class="com.sibu.orderHelper.common.redis.RedisDaoTool" />
	
    <!-- 对string操作的封装 -->  
    <bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"  
        p:connection-factory-ref="jedisConnectionFactory" />
          
</beans>