cache complete cache configuration

 

Complete cache configuration:

When switching the cache, the manager of the cacheManager can be changed, and the other annotations can be used.

 

 

<?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">

    <!-- Enable cache annotations-->

  <cache:annotation-driven/>

<!-- redis start-->

    <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>

 

<!-- in spring-cache. The serialization has been done in xml, so it is commented out here -->

<!-- Redis serialization, used to convert N objects into 1 Key -->

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

 

<!-- Remove \xac\xed\x00\x05t\x00\t in front of the Redis key -->

<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 cache manager -->

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

c:template-ref="jedisTemplate" /> 

<!-- redis end-->

   

</beans>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326484839&siteId=291194637