spring - 如何将 apache ignite 配置为缓存 api 和 spring 缓存提供程序?
问题描述
我想使用 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 应用程序上下文,然后它尝试使用其中一个类中的方法将IgniteConfiguration
实例作为 spring bean获取getBeansOfType()
,并且从那里它没有获取配置实例并抛出上述内容例外。
如 Ignite 文档中所述,我在in 中使用相同的gridName
或instanceName
属性。SpringCacheManager
spring-cache.xml
有人可以检查这个问题吗?另外我不确定我是否遵循正确的方法。首先,我用ignite-config.xml
和盯着 ignite 节点,IgniteSpring.start
一旦节点启动,我就用 进行初始化spring-cache.xml
以Ignition.start
配置Ignite
为SpringCacheManager
.
解决方案
这也在 Apache Ignite 用户论坛上进行了讨论:http: //apache-ignite-users.70518.x6.nabble.com/how-to-configure-apache-ignite-as-cache-api-and-as-spring-缓存提供者-td24068.html