鉴于我有实体:
@Entity
public class NotificationType implements Serializable {
// enum
private DeliveryPriority deliveryPriority;
private long sortOrder;
// TimeStringInterval class implements Serializable
private TimeStringInterval deliveryTimeWindow;
// enum
private DeliveryGroup deliveryGroup = DeliveryGroup.IMMEDIATE;
protected String code;
@Id
public String getCode() {
return code;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CodedEntity)) return false;
CodedEntity<?> that = (CodedEntity<?>) o;
return Objects.equals(getCode(), that.getCode());
}
@Override
public int hashCode() {
return Objects.hashCode(getCode());
}
}
和Spring Data存储库以查找NotificationType实例
@Repository
@CacheConfig(cacheNames = NOTIFICATION_TYPE_CACHE_NAME)
public interface NotificationTypeRepository extends JpaRepository<NotificationType, String> {
@Override
@Cacheable
List<NotificationType> findAll();
}
和findAll
方法是可缓存的。
我的Hazelcast配置为:
@Bean(destroyMethod = "shutdown")
public HazelcastInstance hazelcastInstance() {
HazelcastInstance hazelcastInstance = new HazelcastInstanceFactory(hazelCastConfig()).getHazelcastInstance();
return hazelcastInstance;
}
@Bean
public Config hazelCastConfig() {
Config config = new Config("hazelcast")
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true).setMembers("localhost");
config.getSerializationConfig().setEnableCompression(true);
LockConfig lockConfig = new LockConfig();
lockConfig.setName("locks");
config.addLockConfig(lockConfig);
ListConfig listConfig = new ListConfig();
listConfig.setName("lists");
config.addListConfig(listConfig);
return config;
}
当我执行findAll()
并且hazelcast试图将列表放入缓存时,它会抛出HazelcastSerializationException
:
2019-01-17 16:12:20.762 ERROR --- [hz.ntf-cache.partition-operation.thread-7][][] SetOperation : [localhost]:5701 [ntf-cluster-1547735979367] [3.11.1] There is no suitable de-serializer for type 1921036036. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.
com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable de-serializer for type 1921036036. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.newHazelcastSerializationException(AbstractSerializationService.java:238) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.readObject(AbstractSerializationService.java:265) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.internal.serialization.impl.ByteArrayObjectDataInput.readObject(ByteArrayObjectDataInput.java:574) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.internal.serialization.impl.ArrayListStreamSerializer.read(ArrayListStreamSerializer.java:49) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.internal.serialization.impl.ArrayListStreamSerializer.read(ArrayListStreamSerializer.java:31) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:187) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.map.impl.record.ObjectRecordFactory.newRecord(ObjectRecordFactory.java:37) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.map.impl.recordstore.AbstractRecordStore.createRecord(AbstractRecordStore.java:111) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.map.impl.recordstore.AbstractEvictableRecordStore.createRecord(AbstractEvictableRecordStore.java:55) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.map.impl.recordstore.DefaultRecordStore.putInternal(DefaultRecordStore.java:701) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.map.impl.recordstore.DefaultRecordStore.set(DefaultRecordStore.java:680) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.map.impl.operation.SetOperation.run(SetOperation.java:39) ~[hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.spi.Operation.call(Operation.java:170) [hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:208) [hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:197) [hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:147) [hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:125) [hazelcast-3.11.1.jar:3.11.1]
at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:110) [hazelcast-3.11.1.jar:3.11.1]
该异常的原因是什么?
我应该如何解决此类问题?
异常消息非常隐秘。
我试图调试可以工作的对象列表,并将其与该列表进行比较,但是我发现没有明显的区别。
问题发生在Windows计算机上,最新的hazelcast版本
答案 0 :(得分:-1)
我添加了
private static final long serialVersionUID = 1L;
一切都开始正常工作。
在official hazelcast documentation中也建议:
要消除类兼容性问题,建议您添加一个
serialVersionUID