spring-cacheAnnotations.xml
3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
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">
<!-- 启用 缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一定要声明在spring主配置文件中才会生效 -->
<cache:annotation-driven cache-manager="cacheManager"/>
<!-- spring自己的换管理器,这里定义了两个缓存位置名称 ,既注解中的value -->
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.data.redis.cache.RedisCache">
<constructor-arg name="name" value="rc"/>
<constructor-arg name="expiration" value="1800000"/>
<!--<constructor-arg name="expiration" value="-1"/>-->
<constructor-arg name="prefix" value=""/>
<constructor-arg name="template" ref="cache.redisTemplate"/>
<!--<property name="redisTemplate" ref="redisTemplate" />-->
<!--<property name="name" value="default"/>-->
</bean>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean">
<property name="name" value="default"/>
</bean>
</set>
</property>
</bean>
<!-- redis 相关配置 -->
<bean id="cache.jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!-- <property name="maxActive" value="1000" /> -->
<property name="maxIdle" value="500"/>
<!-- <property name="maxWait" value="1000" /> -->
<property name="testOnBorrow" value="true"/>
</bean>
<bean id="cache.jedis.shardInfo1" class="redis.clients.jedis.JedisShardInfo">
<constructor-arg index="0" value="${project.redis.host1}"/>
<constructor-arg index="1" value="${project.redis.port1}"/>
</bean>
<bean id="cache.connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="usePool" value="true"/>
<property name="poolConfig" ref="cache.jedisPoolConfig"/>
<property name="shardInfo" ref="cache.jedis.shardInfo1"/>
</bean>
<bean id="cache.redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="cache.connectionFactory"/>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
</bean>
<!-- redis custom 配置 -->
<bean id="customJedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!-- <property name="maxTotal" value="1000" /> -->
<property name="maxIdle" value="500" />
<property name="maxWaitMillis" value="1000" />
<property name="testOnBorrow" value="true" />
</bean>
<bean id="customShardInfo" class="redis.clients.jedis.JedisShardInfo">
<constructor-arg index="0" value="${project.redis.host1}" />
<constructor-arg index="1" value="${project.redis.port1}" />
</bean>
<bean id="customShardedJedisPool" class="redis.clients.jedis.ShardedJedisPool">
<constructor-arg index="0" ref="customJedisPoolConfig" />
<constructor-arg index="1">
<list>
<ref bean="customShardInfo" />
</list>
</constructor-arg>
</bean>
</beans>