阅读背景:

spring redis 注解实现缓存机制

来源:互联网 

1、xml配置

 <bean id="poolConfigTax" class="redis.clients.jedis.JedisPoolConfig">  
        <property name="maxIdle" value="${redis_tax.maxIdle}" />  
        <property name="minIdle" value="${redis_tax.minIdle}" />  
        <property name="maxTotal" value="${redis_tax.maxTotal}" />
        <property name="testOnBorrow" value="${redis_tax.testOnBorrow}" />  
    </bean>  
    <!-- Tax redis 数据库  -->
    <bean id="connectionFactoryTax" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"   
        p:host-name="${redis_tax.host}" p:port="${redis_tax.port}" p:password="${redis_tax.pass}"  p:pool-config-ref="poolConfigTax"
        p:database="0"/>  
    <!--redis操作模版,使用该对象可以操作redis  -->  
    <bean id="redisTemplateTax" class="org.springframework.data.redis.core.RedisTemplate" >    
        <property name="connectionFactory" ref="connectionFactoryTax" />    
        <!--如果不配置Serializer,那么存储的时候缺省使用String,如果用User类型存储,那么会提示错误User can't cast to String!!  -->    
        <property name="keySerializer" >    
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />    
        </property>    
        <property name="valueSerializer" >    
            <bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />    
        </property>    
        <property name="hashKeySerializer">    
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>    
        </property>    
        <property name="hashValueSerializer">    
            <bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>    
        </property>    
        <!--开启事务  -->  
        <property name="enableTransactionSupport" value="false"></property>  
    </bean>   
    <!-- 配置RedisCacheManager -->
    <bean id="redisCacheManager" class="org.springframework.data.redis.cache.RedisCacheManager">
        <constructor-arg name="redisOperations" ref="redisTemplateTax" />
    </bean>
    <cache:annotation-driven cache-manager="redisCacheManager"/>
 <bean id="poolConfigTax" class="



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: