最近在项目中需要用到infinispan和redis两个框架,参照官方配置指导infinispan-redis配置,在eclipse中进行配置设置总是提示错误信息(不知道是哪里写错了,还是怎么的);后面经过多次改写测试,如下配置就不会提示错误信息。 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
| <?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:8.0
urn:infinispan:config:store:redis:8.0
http://www.infinispan.org/schema ... edis-config-8.0.xsd
http://www.infinispan.org/schemas/infinispan-config-8.0.xsd"
xmlns="urn:infinispan:config:8.0"
xmlns:redis="urn:infinispan:config:store:redis:8.0" >
<cache-container default-cache="PLATFORM-DATA-CACHE">
<jmx domain="org.infinispan" duplicate-domains="true">
</jmx>
<local-cache name="platformDataCache" >
<persistence passivation="false">
<redis-store topology="server" password="pwd4redis" xmlns="urn:infinispan:config:store:redis:8.0"
socket-timeout="10000" connection-timeout="10000">
<redis-server host="192.168.1.101" port="6379" />
<connection-pool min-idle="15" max-idle="1000" max-total="2000"
min-evictable-idle-time="300" time-between-eviction-runs="1800" />
</redis-store>
</persistence>
</local-cache>
</cache-container>
</infinispan>
|
在spring-context.xml中的配置如下: 1
2
3
4
5
6
7
8
9
10
| <bean id="cacheManager" class="org.infinispan.manager.DefaultCacheManager">
<constructor-arg name="configurationFile" value="infinispan.xml">
</constructor-arg>
</bean>
<bean id="platformCache" factory-bean="cacheManager" factory-method="getCache">
<!-- 可以添加constructor-args参数获取对应的cache实例,无此参数则获取默认cache实例 -->
<constructor-arg name="cacheName" value="platformDataCache">
</constructor-arg>
</bean>
|
在java代码中采用注解的方式:
1
2
3
4
5
6
7
8
9
10
11
12
13
| public class InfinispanCache {
@Resource(name = "platformCache")
private Cache<String, Object> secondCache;
public Cache<String, Object> getSecondCache() {
return secondCache;
}
public void setSecondCache(Cache<String, Object> secondCache) {
this.secondCache = secondCache;
}
//其他代码
}
|
或者在spring-context.xml中定义bean依赖:
1
2
3
| <bean id="secondCacheManager" class="com.test.data.cache.InfinispanCache">
<property name="secondCache" ref="platformCache" />
</bean>
|
按照上面的配置设置就完成对infinispan-redis的集成,需要特别注意的是log级别不能是debug,debug级别时启动会报infinispan初始化错误(这里不知道是怎么回事)。
|