Infinispan-Redis配置使用

來源:互聯網
上載者:User

標籤:緩衝 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配置使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.