hazelcast分布式查询提供HazelcastSerializationException

时间:2016-11-20 23:15:59

标签: java hazelcast

我是Hazelcast的新手。我试图在IMap上使用分布式查询,IMap又将自定义Java对象存储为值(字符串键)。将数据添加到地图是顺利的,即使获取数据也是小菜一碟,但是当我尝试使用谓词时,我得到了这个美丽的信息:

  

INFO:hz.client_0 [dev] [3.7.2] HazelcastClient 3.7.2(20161004 -   540b01c)是CLIENT_CONNECTED线程中的异常" main"   com.hazelcast.nio.serialization.HazelcastSerializationException:   java.lang.ClassNotFoundException:com.test.hazel.Customer at   com.hazelcast.internal.serialization.impl.JavaDefaultSerializers $ JavaSerializer.read(JavaDefaultSerializers.java:224)     在   com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:46)     在   com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:172)     在   com.hazelcast.query.impl.CachedQueryEntry.getValue(CachedQueryEntry.java:70)     在   com.hazelcast.query.impl.CachedQueryEntry.getTargetObject(CachedQueryEntry.java:103)     在   com.hazelcast.query.impl.QueryableEntry.extractAttributeValue(QueryableEntry.java:81)     在   com.hazelcast.query.impl.QueryableEntry.getAttributeValue(QueryableEntry.java:48)     在   com.hazelcast.query.impl.predicates.AbstractPredicate.readAttributeValue(AbstractPredicate.java:130)     在   com.hazelcast.query.impl.predicates.AbstractPredicate.apply(AbstractPredicate.java:55)     在   com.hazelcast.query.impl.predicates.AndPredicate.apply(AndPredicate.java:116)     在   com.hazelcast.map.impl.query.MapQueryEngineImpl.queryTheLocalPartition(MapQueryEngineImpl.java:349)     在   com.hazelcast.map.impl.query.MapQueryEngineImpl.querySequential(MapQueryEngineImpl.java:251)     在   com.hazelcast.map.impl.query.MapQueryEngineImpl.queryUsingFullTableScan(MapQueryEngineImpl.java:240)     在   com.hazelcast.map.impl.query.MapQueryEngineImpl.querySafelyUsingFullTableScan(MapQueryEngineImpl.java:218)     在   com.hazelcast.map.impl.query.MapQueryEngineImpl.queryLocalPartitions(MapQueryEngineImpl.java:133)     在   com.hazelcast.map.impl.query.QueryOperation.run(QueryOperation.java:51)     在   com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:181)     在   com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl.run(OperationExecutorImpl.java:375)     在   com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl.runOrExecute(OperationExecutorImpl.java:402)     在   com.hazelcast.spi.impl.operationservice.impl.Invocation.doInvokeLocal(Invocation.java:283)     在   com.hazelcast.spi.impl.operationservice.impl.Invocation.doInvoke(Invocation.java:268)     在   com.hazelcast.spi.impl.operationservice.impl.Invocation.invoke0(Invocation.java:232)     在   com.hazelcast.spi.impl.operationservice.impl.Invocation.invoke(Invocation.java:207)     在   com.hazelcast.spi.impl.operationservice.impl.InvocationBuilderImpl.invoke(InvocationBuilderImpl.java:59)     在   com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.createInvocations(AbstractMapQueryMessageTask.java:109)     在   com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.invokeOnMembers(AbstractMapQueryMessageTask.java:90)     在   com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.call(AbstractMapQueryMessageTask.java:79)     在   com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask.processMessage(AbstractCallableMessageTask.java:35)     在   com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:119)     在   com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:99)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)at   com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)     在   com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)     在------提交自------。(未知来源)at   com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolve(InvocationFuture.java:111)     在   com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveAndThrow(InvocationFuture.java:74)     在   com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:150)     在   com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.collectResults(AbstractMapQueryMessageTask.java:122)     在   com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.invokeOnMembers(AbstractMapQueryMessageTask.java:91)     在   com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.call(AbstractMapQueryMessageTask.java:79)     在   com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask.processMessage(AbstractCallableMessageTask.java:35)     在   com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:119)     在   com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:99)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)at   com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)     在   com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)     在------提交自------。(未知来源)at   com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrow(ClientInvocationFuture.java:74)     在   com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrow(ClientInvocationFuture.java:30)     在   com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:158)     在com.hazelcast.client.spi.ClientProxy.invoke(ClientProxy.java:171)     在   com.hazelcast.client.proxy.ClientMapProxy.values(ClientMapProxy.java:1180)     在com.test.hazel.SqlQueryMember.main(SqlQueryMember.java:33)引起   by:java.lang.ClassNotFoundException at   com.hazelcast.client.impl.protocol.ClientExceptionFactory $ 12.createException(ClientExceptionFactory.java:170)     在   com.hazelcast.client.impl.protocol.ClientExceptionFactory.createException(ClientExceptionFactory.java:622)     在   com.hazelcast.client.impl.protocol.ClientExceptionFactory.createException(ClientExceptionFactory.java:589)     在   com.hazelcast.client.spi.impl.ClientInvocationServiceSupport $ ResponseThread.handleClientMessage(ClientInvocationServiceSupport.java:331)     在   com.hazelcast.client.spi.impl.ClientInvocationServiceSupport $ ResponseThread.process(ClientInvocationServiceSupport.java:313)     在   com.hazelcast.client.spi.impl.ClientInvocationServiceSupport $ ResponseThread.doRun(ClientInvocationServiceSupport.java:306)     在   com.hazelcast.client.spi.impl.ClientInvocationServiceSupport $ ResponseThread.run(ClientInvocationServiceSupport.java:283)

这是我的杰作:

public static void main(String[] args) {
    ClientConfig clientConfig = new ClientConfig();
    List<String> addList = new ArrayList<>();
    addList.add("iii.cnt.tll.uu:5701");

    clientConfig.setAddresses(addList);

    HazelcastInstance hz = HazelcastClient.newHazelcastClient(clientConfig);


    IMap<String, Customer> map = hz.getMap("map");

    map.put("1", new Customer("peter", true, 36));
    map.put("2", new Customer("john", false, 40));
    map.put("3", new Customer("roger", true, 20));

    Set<Customer> employees = (Set<Customer>) map.values(new SqlPredicate("active AND age < 30"));
    System.out.println("Employees: " + employees);

    Hazelcast.shutdownAll();
}

我复杂的DTO:

public class Customer implements Serializable {
    private final String id = UUID.randomUUID().toString();

    private String name;
    private boolean active;
    private int age;

    Customer(String name, boolean active, int age) {
        this.active = active;
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Customer{"
                + "active=" + active
                + ", id='" + id + '\''
                + ", name='" + name + '\''
                + ", age=" + age
                + '}';
    }
}

我使用的是3.7.2&#39; Hazelcast&#39;发布。是的,我在服务器节点上的类路径中的Jar中有这些类。

1 个答案:

答案 0 :(得分:1)

找到解决方案。我应该在start.bat文件而不是环境变量上添加classpath。谢谢