Ignite CacheStore实现在服务器端抛出ClassNotFoundException

时间:2016-12-22 10:03:15

标签: java ignite spring-cache

我正在实现CacheStore以在数据库中写入数据asyn。 代码在应用程序内运行Ignite时工作正常,因为" Server"并且数据将保存在数据库中。

有问题的场景: 将远程节点作为服务器和应用程序运行为" client", 启动客户机节点时已启动服务器节点抛出ClassNotFoundException。

以下是我的配置:

服务器

<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="metricsLogFrequency" value="0"/>
    <property name="peerClassLoadingEnabled" value="true"/>
    <property name="marshaller">
            <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
            <!-- Set to false to allow non-serializable objects in examples, default is true. -->
            <property name="requireSerializable" value="false"/>
        </bean>
        </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.zk.TcpDiscoveryZookeeperIpFinder">
                <property name="zkConnectionString" value="localhost:2181"/>
            </bean>
            </property>
        </bean>
    </property>
</bean>

客户:

CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName(name);
cacheConfiguration.setBackups(backup);
cacheConfiguration.setRebalanceMode(CacheRebalanceMode.SYNC);
cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
LruEvictionPolicy evictionPolicy = new LruEvictionPolicy();
evictionPolicy.setMaxSize(maxEntries);
cacheConfiguration.setEvictionPolicy(evictionPolicy);
cacheConfiguration.setEvictSynchronized(true);
cacheConfiguration.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(duration));
cacheConfiguration.setStartSize(100*1024*1024);
cacheConfiguration.setReadThrough(true);
cacheConfiguration.setWriteThrough(true);
cacheConfiguration.setWriteBehindEnabled(true);
cacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cacheConfiguration.setCacheStoreFactory(new FactoryBuilder.SingletonFactory<CacheStore>(cacheStore));



IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
igniteConfiguration.setPeerClassLoadingEnabled(true);
TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
TcpDiscoveryZookeeperIpFinder ipFinder = new TcpDiscoveryZookeeperIpFinder();
ipFinder.setZkConnectionString(zookeeperConString);
tcpDiscoverySpi.setIpFinder(ipFinder);

OptimizedMarshaller marshaller = new OptimizedMarshaller();
marshaller.setRequireSerializable(false);

igniteConfiguration.
                setCacheConfiguration(cacheConfiguration).
                setClientMode(isClient);
igniteConfiguration.setDiscoverySpi(tcpDiscoverySpi);
igniteConfiguration.setMarshaller(marshaller).
                setGridName(gridName).
                setMetricsLogFrequency(0);
SpringCacheManager springCacheManager = new SpringCacheManager();
springCacheManager.setConfiguration(igniteConfiguration);

现在,我不想在服务器节点上部署CacheStore,所以我启用了peerclassloading。但抛出相同的异常,所以我在互联网上检查并将其atomicitymode更改为Transaction,因此每次都会使用Client的CacheStore。 但仍面临同样的问题。

1 个答案:

答案 0 :(得分:1)

CacheConfiguration中的所有类都应该在所有节点上都可用。 P2P类加载不适用于CacheStore。您需要手动部署类。