码迷,mamicode.com
首页 > 其他好文 > 详细

Infinispan-Redis配置使用

时间:2016-01-18 21:03:15      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:缓存 cache infinispan redis

最近在项目中需要用到infinispanredis两个框架,参照官方配置指导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配置使用

标签:缓存 cache infinispan redis

原文地址:http://tener.blog.51cto.com/1065457/1736185

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!