Hazelcast可序列化地图ClassNotFound异常 [英] Hazelcast Serializable Map ClassNotFound Exception

查看:66
本文介绍了Hazelcast可序列化地图ClassNotFound异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个简单的Web应用程序中实现Hazelcast.

I am trying to implement Hazelcast in a simple web application.

我正在尝试将自定义对象存储到我的Hazelcast地图中,并已在Bid对象类中实现了带有必要导入的Serializable.

I am trying to store a custom object into my Hazelcast Map and have implemented Serializable in my Bid Object Class with the necessary imports.

import java.io.Serializable;

这是类对象的片段.

public class Bid implements Serializable{

private String bidId;      
private String stock;
private int price;
private String userId;
private Date date;

这里是与本教程一样的语法,用于将Bid对象存储到Map中,其中newBid是Bid对象.

Here are the syntax as with the tutorial to store the Bid Object into the Map where newBid is a Bid Object.

Config cfg = new Config();
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);    

Map<String, Bid> mapBids = instance.getMap("bids");
        mapBids.put(newBid.getUserId(), newBid);

我的Hazelcast节点已启动并正在运行,但是当我查询出价地图时,出现以下错误.

My Hazelcast nodes are up and running but when I query the bids map, I get the following error.

com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.Class
NotFoundException: aa.Bid
        at com.hazelcast.nio.serialization.DefaultSerializers$ObjectSerializer.r
ead(DefaultSerializers.java:190)
        at com.hazelcast.nio.serialization.StreamSerializerAdapter.read(StreamSe
rializerAdapter.java:59)
        at com.hazelcast.nio.serialization.SerializationServiceImpl.toObject(Ser
ializationServiceImpl.java:221)
        at com.hazelcast.spi.impl.NodeEngineImpl.toObject(NodeEngineImpl.java:15
6)
        at com.hazelcast.map.MapService.toObject(MapService.java:773)
        at com.hazelcast.map.proxy.MapProxyImpl.entrySet(MapProxyImpl.java:502)
        at com.hazelcast.examples.TestApp.handleMapEntries(TestApp.java:882)
        at com.hazelcast.examples.TestApp.handleCommand(TestApp.java:371)
        at com.hazelcast.examples.TestApp.start(TestApp.java:187)
        at com.hazelcast.examples.TestApp.main(TestApp.java:1641)

Caused by: java.lang.ClassNotFoundException: aa.Bid
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:109)
        at com.hazelcast.nio.IOUtil$1.resolveClass(IOUtil.java:89)
        at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
        at java.io.ObjectInputStream.readClassDesc(Unknown Source)
        at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
        at java.io.ObjectInputStream.readObject0(Unknown Source)
        at java.io.ObjectInputStream.readObject(Unknown Source)
        at com.hazelcast.nio.serialization.DefaultSerializers$ObjectSerializer.r
ead(DefaultSerializers.java:185)
        ... 9 more

该对象类与我的Web应用程序位于同一文件夹中,具有必需的导入语法,但未读取它.我也已将CLASSPATH添加到我的Hazelcast jar文件中.

The object class is located in the same folder as my web app with the necessary import syntax but it is not reading it. I have added the CLASSPATH to my Hazelcast jar file as well.

为了让Serializable工作,我必须在Bid类对象中进行Transient的任何变量设置吗?还是我错过了什么?

Are there any variable that I have to make Transient in my Bid class object in order for Serializable to work? Or am I missing something?

推荐答案

在尝试将"MyClass"的实例放入相关iMap时,我使用远程两节点群集遇到了同样的问题.我以为我需要分发包含"MyClass"的罐子的时候扯了一下头发,但意识到问题是hazelcast.xml文件中的定义指定了内存格式的OBJECT ...

I was experiencing this same issue using a remote two-node cluster when trying to put an instance of 'MyClass' into the relevant iMap. I was tearing my hair out thinking that I'd need to distribute the jar containing 'MyClass' but realised that the problem was that the definition within hazelcast.xml file was specifying an in-memory-format of OBJECT...

<in-memory-format>OBJECT</in-memory-format>

我将此值更改为BINARY,一切开始正常工作.

I changed this value to BINARY and everything started working.

<in-memory-format>BINARY</in-memory-format>

nb.我现在在集群中有许多不同的映射,其中一些定义为OBJECT,一些定义为BINARY.

nb. I now have a number of different maps within the cluster, some of which are defined as OBJECT and some as BINARY.

我希望这对外面的人有帮助!

I hope this helps someone out there!

这篇关于Hazelcast可序列化地图ClassNotFound异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆