cache完整的缓存配置

完整的缓存配置:

切换缓存的时候cacheManager他的管理器变下即可,注解其他照用。

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

  xmlns:cache="http://www.springframework.org/schema/cache"

  xmlns:c="http://www.springframework.org/schema/c"

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  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/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

    <!-- 开启缓存注解 -->

  <cache:annotation-driven/>

<!-- redis开始 -->

    <bean id="propertyConfigurerRedis" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

        <property name="order" value="1" />

        <property name="ignoreUnresolvablePlaceholders" value="true" />

        <property name="locations">

            <list>

                <value>classpath:config_spring/redis.properties</value>

            </list>

        </property>

    </bean>

    <!-- Jedis ConnectionFactory -->

    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">

        <property name="maxTotal" value="${redis.maxTotal}" />

        <property name="maxIdle" value="${redis.maxIdle}" />

        <property name="timeBetweenEvictionRunsMillis" value="${redis.minEvictableIdleTimeMillis}" />

        <property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}" />

        <property name="testOnBorrow" value="${redis.testOnBorrow}" />

    </bean>

    <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">

        <property name="hostName" value="${redis.host}" />

        <property name="port" value="${redis.port}" />     

        <!-- <property name="password" value="${redis.pass}" /> -->

        <property name="poolConfig" ref="jedisPoolConfig" />

    </bean>

<!-- 在spring-cache。xml里已经做了序列化,这里就注释掉了 -->

<!-- Redis序列化,用于转换N个对象存在1个Key里 -->

<bean id="redisSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>

<!-- 消除Redis的key前面的\xac\xed\x00\x05t\x00\t这些东西 -->

<bean id="stringRedisSerializer"

class="org.springframework.data.redis.serializer.StringRedisSerializer" />

<bean id="jedisTemplate" class="org.springframework.data.redis.core.RedisTemplate"

p:keySerializer-ref="stringRedisSerializer" p:hashKeySerializer-ref="stringRedisSerializer"

p:connection-factory-ref="jedisConnectionFactory" />

<!-- redis缓存管理器 -->

<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager"

c:template-ref="jedisTemplate" /> 

<!-- redis结束 -->

   

</beans>

猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2317761