Serialization Hazelcast在独立进程上没有为命名空间0注册DataSerializerFactory

Serialization Hazelcast在独立进程上没有为命名空间0注册DataSerializerFactory,serialization,deserialization,hazelcast,Serialization,Deserialization,Hazelcast,正在尝试在独立进程上设置启用tcp ip的HazelCast群集。 我的班级看起来像这样 public class Person implements Serializable{ private static final long serialVersionUID = 1L; int personId; String name; Person(){}; //getters and setters } Hazelcast加载为 final Config config = crea

正在尝试在独立进程上设置启用tcp ip的HazelCast群集。 我的班级看起来像这样

public class Person implements Serializable{
 private static final long serialVersionUID = 1L;
 int    personId;
 String name;
 Person(){};
 //getters and setters
}
Hazelcast加载为

final Config config = createNewConfig(mapName);
HazelcastInstance node = Hazelcast.newHazelcastInstance(config);`

Config createNewConfig(mapName){
final PersonStore personStore = new PersonStore();
  XmlConfigBuilder configBuilder = new XmlConfigBuilder();


Config config = configBuilder.build();
  config.setClassLoader(LoadAll.class.getClassLoader());
  MapConfig mapConfig = config.getMapConfig(mapName);
  MapStoreConfig mapStoreConfig = new MapStoreConfig();
  mapStoreConfig.setImplementation(personStore);
  return config;
}
我的myhazelcast配置有这个

<tcp-ip enabled="true">
                <member>machine-1</member>
                <member>machine-2</member>
</tcp-ip>

任何帮助都非常有用。

解决了我的问题,我在hazelcast wm中有一个pom.xml,所以我的捆绑罐中没有实际的hazelcast罐。包括该选项修复了我的问题。

请注意,当您试图在同一个VM中使用多个Hazelcast实例,但初始化来自不同捆绑包的实例时,在OSGi环境中也会出现相同的“No DataSerializerFactory registered for namespace:0”错误消息。原因是com.hazelcast.util.ServiceLoader.findHighestReachableClassLoader()方法有时会在hazelcast初始化期间选择错误的类加载器(因为它不会总是选择您在配置中设置的类加载器),然后它会以DataSerializerFactory实例的空列表结束(因此导致错误消息,即找不到id为0的请求工厂)。下面显示了一种利用Java的上下文类加载器解决该问题的方法:

private HazelcastInstance createHazelcastInstance() {  

    // Use the following if you're only using the Hazelcast data serializers   
    final ClassLoader classLoader = Hazelcast.class.getClassLoader();

    // Use the following if you have custom data serializers that you need
    // final ClassLoader classLoader = this.getClass().getClassLoader();

    final com.hazelcast.config.Config config = new com.hazelcast.config.Config();
    config.setClassLoader(classLoader);
    final ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);
        return Hazelcast.newHazelcastInstance(config);
    } finally {
        if(previousContextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(previousContextClassLoader);
        }
    }
}

我浏览了这个问题[link](),但我不想使用自定义序列化,而是想使用java提供的默认序列化。@noctarius,请您插话,我已经看到您对类似问题的许多其他评论。感谢您发布您自己问题的答案。如果其他工程师遇到同样的问题,这将非常有用。
private HazelcastInstance createHazelcastInstance() {  

    // Use the following if you're only using the Hazelcast data serializers   
    final ClassLoader classLoader = Hazelcast.class.getClassLoader();

    // Use the following if you have custom data serializers that you need
    // final ClassLoader classLoader = this.getClass().getClassLoader();

    final com.hazelcast.config.Config config = new com.hazelcast.config.Config();
    config.setClassLoader(classLoader);
    final ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);
        return Hazelcast.newHazelcastInstance(config);
    } finally {
        if(previousContextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(previousContextClassLoader);
        }
    }
}