私は、永続化レイヤとしてcassandra 2.1.9を使用してApache Ignite 2.3を使用しています。 私は、dbからデータを保存して取得するcacheStoreFactoryクラスを使用しています。 このクラスのいくつかの依存関係を自動配線していますが、nullになっています。ここスプリングブートautowiredオブジェクトがignite persistence cachestoreファクトリクラスでヌルに設定されています
私のサンプルのIgnite confifurationファイルされる:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
">
<description>Main Spring file for ignite configuration.</description>
<bean id="cacheIgniteBean" class="org.apache.ignite.IgniteSpringBean">
<property name="configuration">
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<property name="dataRegionConfigurations">
<list>
<!--
Defining a data region that will consume up to 2 GB of RAM.
-->
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<!-- Custom region name. -->
<property name="name" value="2GB_Region"/>
<!-- 500 MB initial size (RAM). -->
<property name="initialSize" value="#{500L * 1024 * 1024}"/>
<!-- 2 GB maximum size (RAM). -->
<property name="maxSize" value="#{2L * 1024 * 1024 * 1024}"/>
<!-- Enabling RANDOM_LRU eviction for this region. -->
<property name="pageEvictionMode" value="RANDOM_LRU"/>
</bean>
</list>
</property>
</bean>
</property>
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="item"/>
<property name="cacheMode" value="PARTITIONED"/>
<property name="atomicityMode" value="ATOMIC"/>
<property name="backups" value="0"/>
<property name="cacheStoreFactory">
<bean class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
<constructor-arg value="com.tgt.gom.cacheserver.store.ItemCacheStore"/>
</bean>
</property>
<property name="readThrough" value="${ignite.config.cache.item.readThrough}"/>
<property name="writeThrough" value="${ignite.config.cache.item.writeThrough}"/>
<property name="writeBehindEnabled" value="${ignite.config.cache.item.writeBehindEnabled}"/>
<property name="writeBehindFlushSize"
value="${ignite.config.cache.item.writeBehindFlushSize}"/>
<property name="writeBehindFlushFrequency"
value="${ignite.config.cache.item.writeBehindFlushFrequency}"/>
<property name="writeBehindFlushThreadCount"
value="${ignite.config.cache.item.writeBehindFlushThreadCount}"/>
<property name="writeBehindBatchSize"
value="${ignite.config.cache.item.writeBehindBatchSize}"/>
</bean>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="location"/>
<property name="cacheMode" value="PARTITIONED"/>
<property name="atomicityMode" value="ATOMIC"/>
<property name="backups" value="0"/>
<property name="cacheStoreFactory">
<bean class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
<constructor-arg value="com.tgt.gom.cacheserver.store.LocationCacheStore"/>
</bean>
</property>
<property name="readThrough" value="${ignite.config.cache.item.readThrough}"/>
<property name="writeThrough" value="${ignite.config.cache.item.writeThrough}"/>
<property name="writeBehindEnabled" value="${ignite.config.cache.item.writeBehindEnabled}"/>
<property name="writeBehindFlushSize"
value="${ignite.config.cache.item.writeBehindFlushSize}"/>
<property name="writeBehindFlushFrequency"
value="${ignite.config.cache.item.writeBehindFlushFrequency}"/>
<property name="writeBehindFlushThreadCount"
value="${ignite.config.cache.item.writeBehindFlushThreadCount}"/>
<property name="writeBehindBatchSize"
value="${ignite.config.cache.item.writeBehindBatchSize}"/>
</bean>
</list>
</property>
<!--<property name="includeEventTypes">
<util:constant static-field="org.apache.ignite.events.EventType.EVTS_TASK_EXECUTION"/>
</property>-->
<property name="failureDetectionTimeout" value="5000"/>
<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">
<!-- <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"> -->
<property name="addresses">
<list>
<value>127.0.0.1:47500..47509</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
</property>
</bean>
</beans>
ここでは私のItemCacheStoreクラスのコードです:
@Slf4j
@Service
public class ItemCacheStore extends CacheStoreAdapter<String, ItemV1DTO> implements Serializable {
private static final long serialVersionUID = 1L;
@Autowired
private ItemRepository itemRepository;
@Autowired
private ItemCacheStoreAsync itemCacheStoreAsync;
private static final String LOG_OP_INFO = "Item_Cache_Store";
@Override
public ItemV1DTO load(String item_id) throws CacheLoaderException {
ItemV1DTO itemV1DTO = null;
System.out.println("in item cache store ");
try {
ItemEntity itemEntity = itemRepository.findOne(item_id);
if (itemEntity != null) {
itemV1DTO = mapToItemDTO(itemEntity);
}
} catch (Exception e) {
throw new CacheLoaderException("failed to load item data from cassandra" + e.getMessage());
}
return itemV1DTO;
}
}
ItemCacheStoreクラスでロードメソッドが呼び出されたときに、itemRepository
フィールドはnull
です。しかし、別のコントローラクラスで同じItemRepository
のBeanをオートワイヤすると、正常に動作します。私が気づい
もう一つは、私がItemCacheStore
クラスで@PostConstruct
アノテーションで一つの方法を置くならば、その時点で私はItemRepository
の依存性が注入されてしまったが、loadメソッドが呼び出されたときに、それが再びnull
で見ることができるということです。
<property name="cacheStoreFactory">
<bean class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
<constructor-arg value="com.tgt.gom.cacheserver.store.ItemCacheStore"/>
</bean>
</property>
あなたがタイプFactoryBuilder
ののSpring Beanを作成していると、あなたはクラス名ItemCacheStore
を渡す: