当前位置: 首页 > 知识库问答 >
问题:

Java.lang.ClassNotFoundException在hazelcast中在服务器级别配置的MapLoader

赵俊晤
2023-03-14

我使用的是多节点hazelcast(3.11版本)集群。我的用例是,在hazelcast启动期间,我希望每个成员加载IMAP中的数据。我在hazelcast.xml中为每个节点配置了映射存储配置

我已经在hazelcast.xml中添加了mapstore配置。该文件被放置在每个hazelcast节点的bin文件夹中。

<?xml version="1.0" encoding="UTF-8"?>
<hazelcast
        xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.3.xsd"
        xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <properties>
        <property name="hazelcast.initial.min.cluster.size">2</property>
    </properties>

<management-center enabled="true">
    http://localhost:8080/hazelcast-mancenter
</management-center>

    <network>
        <port auto-increment="true">5701</port>
        <join>
            <multicast enabled="false">
                <multicast-group>224.2.2.3</multicast-group>
                <multicast-port>2434</multicast-port>
                <multicast-timeout-seconds>1</multicast-timeout-seconds>
            </multicast>
            <tcp-ip enabled="true" connection-timeout-seconds="3">
                <member>127.0.0.1:5701</member>
                <member>127.0.0.1:5702</member>
            </tcp-ip>
        </join>
        <interfaces enabled="true">
            <interface>127.0.0.1</interface>
        </interfaces>
    </network>


<map name="testmap">
    <backup-count>1</backup-count>
    <time-to-live-seconds>0</time-to-live-seconds>
    <max-idle-seconds>0</max-idle-seconds>

    <map-store enabled="true">
        <class-name>com.bm.mapstore.OnboardingMapLoader</class-name>
        <write-delay-seconds>0</write-delay-seconds>
    </map-store>
</map>

</hazelcast>
Caused by: java.lang.ClassNotFoundException: com.bm.mapstore.OnboardingMapLoader
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:288)
    at com.hazelcast.nio.ClassLoaderUtil.newInstance0(ClassLoaderUtil.java:212)
    at com.hazelcast.nio.ClassLoaderUtil.newInstance(ClassLoaderUtil.java:193)
    at com.hazelcast.map.impl.mapstore.StoreConstructor.getStoreFromClassOrNull(StoreConstructor.java:81)
    at com.hazelcast.map.impl.mapstore.StoreConstructor.createStore(StoreConstructor.java:46)
    at com.hazelcast.map.impl.mapstore.BasicMapStoreContext.create(BasicMapStoreContext.java:124)
    at com.hazelcast.map.impl.mapstore.MapStoreContextFactory.createMapStoreContext(MapStoreContextFactory.java:48)
    at com.hazelcast.map.impl.MapContainer.<init>(MapContainer.java:155)
    at com.hazelcast.map.impl.MapServiceContextImpl$1.createNew(MapServiceContextImpl.java:194)
    at com.hazelcast.map.impl.MapServiceContextImpl$1.createNew(MapServiceContextImpl.java:190)
    at com.hazelcast.util.ConcurrencyUtil.getOrPutSynchronized(ConcurrencyUtil.java:93)
    at com.hazelcast.map.impl.MapServiceContextImpl.getMapContainer(MapServiceContextImpl.java:278)
    at com.hazelcast.map.impl.operation.MapOperationProviders.getOperationProvider(MapOperationProviders.java:47)
    at com.hazelcast.map.impl.MapServiceContextImpl.getMapOperationProvider(MapServiceContextImpl.java:747)
    at com.hazelcast.client.impl.protocol.task.map.AbstractMapPartitionMessageTask.getMapOperationProvider(AbstractMapPartitionMessageTask.java:36)
    at com.hazelcast.client.impl.protocol.task.map.MapGetMessageTask.prepareOperation(MapGetMessageTask.java:54)
    at com.hazelcast.client.impl.protocol.task.AbstractPartitionMessageTask.processMessage(AbstractPartitionMessageTask.java:62)
    at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:123)
    at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.doRun(AbstractMessageTask.java:111)
    at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:101)
    at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:161)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:159)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:127)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:110)
Apr 19, 2019 1:51:08 PM com.hazelcast.client.connection.ClientConnectionManager
import java.util.Map;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;

public class AppTest {

    public static void main(String[] args) {

        ClientConfig config = new ClientConfig();
        String[] addresses = { "localhost:5701", "localhost:5702" };
        config.getNetworkConfig().addAddress(addresses);

        HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(config);

          Map<String, Onboarding>  imap = hazelcastInstance
                .getMap("testmap");
        System.out.println(imap.get("6001"));

        hazelcastInstance.shutdown();
    }

}

Maploader源代码:

  package com.bm.mapstore;

    import java.io.Serializable;
    import java.math.BigInteger;
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.Map;
    import java.util.Set;

    import org.bson.Document;
    import org.bson.codecs.configuration.CodecProvider;
    import org.bson.codecs.configuration.CodecRegistries;
    import org.bson.codecs.configuration.CodecRegistry;
    import org.bson.codecs.pojo.Convention;
    import org.bson.codecs.pojo.Conventions;
    import org.bson.codecs.pojo.PojoCodecProvider;

    import com.bm.entity.Onboarding;
    import com.hazelcast.core.MapLoader;
    import com.mongodb.BasicDBObject;
    import com.mongodb.MongoClient;
    import com.mongodb.MongoClientURI;
    import com.mongodb.client.FindIterable;
    import com.mongodb.client.MongoCollection;
    import com.mongodb.client.MongoCursor;
    import com.mongodb.client.MongoDatabase;

    public class OnboardingMapLoader implements MapLoader<String, Onboarding>, Serializable {
        private static final long serialVersionUID = 1L;
        private MongoClient mongoClient;
        private MongoDatabase db;
        private MongoCollection collection;
        private String uri = "mongodb://localhost:27017/demodb";

        public MongoClient getMongoClient() {
            return this.mongoClient;
        }

        public void setMongoClient(MongoClient mongoClient) {
            this.mongoClient = mongoClient;
        }

        public MongoDatabase getDb() {
            return this.db;
        }

        public void setDb(MongoDatabase db) {
            this.db = db;
        }

        public OnboardingMapLoader() {
            CodecRegistry pojoCodecRegistry = CodecRegistries
                    .fromRegistries(new CodecRegistry[] { MongoClient.getDefaultCodecRegistry(),
                            CodecRegistries.fromProviders(new CodecProvider[] { PojoCodecProvider.builder()
                                    .conventions(Arrays.asList(new Convention[] { Conventions.ANNOTATION_CONVENTION }))
                                    .automatic(true).build() }) });

            this.mongoClient = new MongoClient(new MongoClientURI(uri));
            this.db = this.mongoClient.getDatabase("dbvadd1").withCodecRegistry(pojoCodecRegistry);
            this.collection = this.db.getCollection("onboarding");
        }

        @Override
        public Onboarding load(String key) {
            System.out.println("---------------inside load key is -----------------" + key);
            BasicDBObject searchQuery = new BasicDBObject();
            searchQuery.put("_id", key);
            Document doc = (Document) collection.find(searchQuery).first();
            Onboarding onboarding = new Onboarding();
            onboarding.setSvcInvkrId(doc.getString("_id"));
            onboarding.setAllowMultiple(doc.getString("allowMultiple"));
            onboarding.setBid(new BigInteger(doc.getString("bid")));
            System.out.println("---------------inside load onboarding is -----------------" + onboarding);
            return onboarding;
        }

        @Override
        public Map<String, Onboarding> loadAll(Collection<String> keys) {
            Map<String, Onboarding> result = new HashMap();
            FindIterable<Document> documents = this.collection.find();
            for (MongoCursor localMongoCursor = documents.iterator(); localMongoCursor.hasNext();) {
                Document doc = (Document) localMongoCursor.next();
                Onboarding onboarding = new Onboarding();
                onboarding.setSvcInvkrId(doc.getString("_id"));
                onboarding.setAllowMultiple(doc.getString("allowMultiple"));
                onboarding.setBid(new BigInteger(doc.getString("bid")));
                result.put(onboarding.getSvcInvkrId(), onboarding);
            }
            System.out.println("---------------inside loadAll result is-----------------" + result);
            return result;
        }

        public Set<String> loadAllKeys() {
            return new HashSet<String>(Arrays.asList("6001", "6002"));
        }

    }

请帮助解决客户端代码中未找到类的异常。

共有1个答案

璩俊雅
2023-03-14

是否验证了OnboardingMaploader.class确实在./user-lib目录中的jar文件中?

 类似资料:
  • 我们正在将我们的应用程序代码从WAS8.0迁移到Liberty17.0.0.1。我们的应用程序使用邮件功能,当用户处理请求时调用该功能。有人能帮助我们配置邮件server.xml.是否必须为server.xml中的标签提供用户和密码?

  • 我想将使用Hazelcast3.12.9作为兑现机制的Spring Boot应用程序升级到Java11和Tomcat9。当我在本地部署时,一切看起来都工作得很好,缓存也成功地工作了。但当应用程序在集群上运行时,我从所有可用的3个节点收到以下错误: Hazelcast自定义程序: 经过几天的调查,我看到了将这些异常抛入并行流中的唯一地方。 奇怪的是,在Java8和Tomcat8中,我没有这个问题。

  • 我正在使用Eclipse Juno,并且通过windows安装程序在我的PC中安装了Apache Tomcat/8.0.0-RC5。当我尝试在Eclipse中定义新服务器时,在Apache下,我没有Tomcat v8.0选项。它在Tomcat v7.0停止。如何让Apache Tomcat v8.0在Eclipse中运行?

  • 我们来看看如何配置服务器端的 SSH 访问。 本例中,我们将使用 authorized_keys 方法来对用户进行认证。 同时我们假设你使用的操作系统是标准的 Linux 发行版,比如 Ubuntu。 首先,创建一个操作系统用户 git,并为其建立一个 .ssh 目录。 $ sudo adduser git $ su git $ cd $ mkdir .ssh && chmod 700 .ssh

  • 服务器配置 当你需要一台服务器的时候,首先需要向你的leader 提出申请,你的 leader 会利用公司的阿里云账户购买服务器实例,并且会把服务器的公网IP以及账号密码发送给你。 以下章节就叙述了当拿到一台全新的阿里云服务器实例时,我们需要怎样的工具以及我们需要经历哪些步骤对服务器进行配置。

  • 我正在尝试让这个gRPC服务器示例与Google Asylo(https://github.com/google/asylo/tree/master/asylo/examples/grpc_server)一起工作。.要初始化服务器,我需要在此配置文件中指定server_address(https://github.com/google/asylo/blob/master/asylo/example