java – “无法反序列化对象”在点燃缓存中插入对象时出错

在字符串键上插入pojoClass对象时发生以下错误.我在Ignite配置中包含了所有事件类型.

我尝试了setStoreKeepBinary(true)并尝试了igniteConfiguration.setPeerClassLoadingEnabled(true)但错误未解决.

我正在使用Apache Ignite 2.1版.

错误日志:

[2017-09-06 16:22:08,043][ERROR][tcp-client-disco-msg-worker-#4%null%]     [TcpDiscoverySpi] Failed to unmarshal discovery data for component: 0
class org.apache.ignite.IgniteCheckedException: Failed to deserialize object with given class loader: sun.misc.Launcher$AppClassLoader@75b84c92
    at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:129)
    at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:94)
    at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:143)
    at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:82)
    at org.apache.ignite.spi.discovery.tcp.internal.DiscoveryDataPacket.unmarshalData(DiscoveryDataPacket.java:274)
    at org.apache.ignite.spi.discovery.tcp.internal.DiscoveryDataPacket.unmarshalGridData(DiscoveryDataPacket.java:131)
    at org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.onExchange(TcpDiscoverySpi.java:1820)
    at org.apache.ignite.spi.discovery.tcp.ClientImpl$MessageWorker.processNodeAddFinishedMessage(ClientImpl.java:1985)
    at org.apache.ignite.spi.discovery.tcp.ClientImpl$MessageWorker.processDiscoveryMessage(ClientImpl.java:1864)
    at org.apache.ignite.spi.discovery.tcp.ClientImpl$MessageWorker.body(ClientImpl.java:1758)
    at org.apache.ignite.spi.IgniteSpiThread.run(IgniteSpiThread.java:62)
Caused by: java.io.InvalidObjectException: Failed to find cache for name: CACHE
    at org.apache.ignite.internal.processors.cache.GridCacheContext.readResolve(GridCacheContext.java:2139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1148)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2036)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
    at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.readExternal(IgniteCacheProxy.java:2782)
    at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:2076)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2025)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2125)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2245)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2125)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2027)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
    at org.apache.ignite.internal.GridEventConsumeHandler.readExternal(GridEventConsumeHandler.java:452)
    at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:2076)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2025)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
    at org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$DiscoveryDataItem.readExternal(GridContinuousProcessor.java:1812)
    at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:2076)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2025)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
    at org.apache.ignite.internal.util.IgniteUtils.readList(IgniteUtils.java:5299)
    at org.apache.ignite.internal.util.IgniteUtils.readCollection(IgniteUtils.java:1739)
    at org.apache.ignite.internal.processors.continuous.GridContinuousProcessor$DiscoveryData.readExternal(GridContinuousProcessor.java:1727)
    at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:2076)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2025)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
    at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:121)
    ... 10 more
Caused by: java.lang.IllegalStateException: Failed to find cache for name: CACHE
    at org.apache.ignite.internal.processors.cache.GridCacheContext.readResolve(GridCacheContext.java:2134)
    ... 49 more

缓存配置:

  CacheConfiguration<String, pojoClass> cacheConfig = new CacheConfiguration<>();
            cacheConfig.setName("CACHE");
            cacheConfig.setBackups(2);
            cacheConfig.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
            cacheConfig.setIndexedTypes(String.class, pojoClass.class);
        //  cacheConfig.setStoreKeepBinary(true);
            IgniteCache<String, pojoClass> Cache = ignite.getOrCreateCache(cacheConfig);

代码插入pojoClass对象时:

PojoClass pojoObj = new PojoClass(key, name,jsonObject);
Cache.put(key, pojoObj);    

这里PojoClass是:

public class PojoClass{
@QuerySqlField
String key;
@QuerySqlField
String name;
@QuerySqlField
JSONObject jsonObject;
public PojoClass(String key, String name,JSONObject jsonObject) {
        this.key = key;
        this.name = name;
        this.jsonObject = jsonObject;
   }
}

最佳答案 在创建缓存和执行事件功能时使用相同的Ignite实例后出现错误我正在使用上面出现的不同Ignite实例.

点赞