【问题标题】:how to configure apache ignite as cache api and as spring cache provider?如何将 apache ignite 配置为缓存 api 和 spring 缓存提供程序?
【发布时间】:2018-09-12 20:15:17
【问题描述】:

我想使用 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>

我正在初始化 ignite 节点,如下所示。

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 应用程序上下文,然后它尝试在其中一个类中使用 getBeansOfType() 方法获取 IgniteConfiguration 实例作为 spring bean 并从在那里它没有得到配置实例并抛出上述异常。

如 Ignite 文档中所述,我在 SpringCacheManagerspring-cache.xml 中使用相同的 gridNameinstanceName 属性。

有人可以检查一下这个问题吗?另外我不确定我是否遵循正确的方法。首先,我使用 ignite-config.xmlIgniteSpring.start 盯着 ignite 节点,一旦节点启动,我将使用 Ignition.start 初始化 spring-cache.xml 以将 Ignite 配置为 SpringCacheManager

【问题讨论】:

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


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-23
    • 2018-10-18
    • 1970-01-01
    • 2020-09-14
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    相关资源
    最近更新 更多