Repository navigation
Expand file tree
/
Copy pathSpringCache.xml
More file actions
38 lines (33 loc) · 2 KB
/
Copy pathSpringCache.xml
File metadata and controls
38 lines (33 loc) · 2 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
<?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:p="http://www.springframework.org/schema/p" xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- Jedis ConnectionFactory -->
<bean id='jedisConnectionFactory' class='org.springframework.data.redis.connection.jedis.JedisConnectionFactory' p:host-name='${redis.host}' p:port='${redis.port}' p:use-pool='true' p:password='${redis.password}' />
<!-- redis template definition -->
<bean id='redisTemplate' class='org.springframework.data.redis.core.RedisTemplate' p:connection-factory-ref='jedisConnectionFactory' />
<!-- 只需要修改cache-manager就可以切换缓存管理器 -->
<cache:annotation-driven mode="proxy" key-generator="customKeyGenerator" cache-manager="simpleCacheManager" />
<bean id="simpleCacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<!-- 同步Map缓存 -->
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean">
<property name="name" value="default" />
</bean>
<!-- Redis緩存 -->
<bean class="com.caozj.cache.RedisCache">
<property name="redisTemplate" ref="redisTemplate" />
<property name="name" value="redis" />
</bean>
</set>
</property>
</bean>
</beans>