標籤:緩衝 cache infinispan redis
最近在項目中需要用到infinispan和redis兩個架構,參照官方配置指導infinispan-redis配置,在eclipse中進行配置設定總是提示錯誤資訊(不知道是哪裡寫錯了,還是怎麼的);後面經過多次改寫測試,如下配置就不會提示錯誤資訊。
<?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/schemas/infinispan-cachestore-redis-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中的配置如下:
<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代碼中採用註解的方式:
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依賴:
<bean id="secondCacheManager" class="com.test.data.cache.InfinispanCache"> <property name="secondCache" ref="platformCache" /> </bean>
按照上面的配置設定就完成對infinispan-redis的整合,需要特別注意的是log層級不能是debug,debug層級時啟動會報infinispan初始化錯誤(這裡不知道是怎麼回事)。
本文出自 “好記性不如爛筆頭” 部落格,請務必保留此出處http://tener.blog.51cto.com/1065457/1736185
Infinispan-Redis配置使用