如何配置apache ignite作为缓存api和spring缓存提供程序?

时间:2018-09-12 20:15:18

标签: spring spring-boot caching ignite spring-cache

我想使用ignite作为缓存API以及spring缓存提供程序。我正在如下的ignite-config.xml文件中运行以下配置

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:cache="http://www.springframework.org/schema/cache"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/cache
                        http://www.springframework.org/schema/cache/spring-cache.xsd"
                        >

<!--    <bean id="cacheIgniteBean" class="org.apache.ignite.IgniteSpringBean">
   <property name="configuration">  -->


<bean class="org.apache.ignite.configuration.IgniteConfiguration">
  <property name="peerClassLoadingEnabled" value="true"/>
  <property name="igniteInstanceName" value="claimgrid"/>
<property name="cacheConfiguration">
                <list>
                    <bean class="org.apache.ignite.configuration.CacheConfiguration">

                        <property name="name" value="T_MST_TEUC_Q_PERCENTAGE"/>
                        <property name="cacheMode" value="REPLICATED"/>
                        <property name="atomicityMode" value="ATOMIC"/>
                        <property name="partitionLossPolicy" value="READ_WRITE_SAFE"/>
                        <property name="backups" value="0"/>
                        <property name="groupName" value="masterData"/>
                        <property name="cacheStoreFactory">
                            <bean class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
                                <constructor-arg value="com.mrm.access.benefits.ms.claim.cache.store.SequesterPercentageModelStore"/>
                            </bean>

                        </property>

                        <property name="readThrough" value="true"/>
                        <property name="writeThrough" value="true"/>

                    </bean>
</list>
</property>



    <property name="discoverySpi">
        <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
            <property name="ipFinder">
                <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                 <property name="addresses">
                        <list>  
                              <value>10.80.211.76</value>
                        </list>
                    </property>
                    </bean>
            </property>
        </bean>
    </property>
</bean>

我正在如下初始化点火节点。

ApplicationContext context= SpringApplication.run(Application.class, args);
Ignite ignite=IgniteSpring.start("ignite-config.xml", context);

节点启动并运行。现在,我正在使用第二个配置文件作为Spring缓存管理器spring-cache.xml

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:cache="http://www.springframework.org/schema/cache"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/cache
                        http://www.springframework.org/schema/cache/spring-cache.xsd"
                        >
<bean id="cacheManager" class="org.apache.ignite.cache.spring.SpringCacheManager">



        <property name="igniteInstanceName" value="claimgrid" />


</bean>
<cache:annotation-driven/>

我正在如下初始化该文件

Ignite ignite=Ignition.start("spring-cache.xml");

我收到以下异常

Caused by: class org.apache.ignite.IgniteCheckedException: Failed to find configuration in: file:/E:/Workspace/ms.claim/spring-cache.xml
    at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:116)
    at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:98)
    at org.apache.ignite.internal.IgnitionEx.loadConfigurations(IgnitionEx.java:744)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:945)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:854)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:724)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:693)
    at org.apache.ignite.Ignition.start(Ignition.java:352)
    ... 2 more

在调试ignite源代码时,我发现ignite在内部使用SpringHelper来获取Spring Application Context,然后尝试使用IgniteConfiguration方法将getBeansOfType()实例作为spring bean获取。其中一个类,从那里不会获取配置实例,并引发上述异常。

如Ignite文档中所述,我在gridName的{​​{1}}中使用相同的instanceNameSpringCacheManager属性。

有人可以检查该问题吗?另外,我不确定我是否遵循正确的方法。首先,我用spring-cache.xmlignite-config.xml盯着点火节点,一旦节点启动,我就用IgniteSpring.start初始化spring-cache.xml以将Ignition.start配置为{{1 }}。

1 个答案:

答案 0 :(得分:1)