这是我所拥有的:
Serializer
。这是我的问题:
Serializer
具有构造函数依赖项,因此无法通过.xml声明它们。Config
之后(即,将Serializer
添加到配置中])不会导致Serializer
被注册。我正在寻找/到目前为止已经尝试过的解决方案:
HazelcastInstance
并以某种方式将其绑定到JCache(不知道该如何实现,甚至不知道是否可行)Serializer
添加到现有的HazelcastInstance
/ Config
(如前所述,似乎不起作用)问题:
有什么方法可以使其正常工作?我是否缺少一些显而易见的东西?我使用的框架错误吗?
假设您以编程方式使用自定义Config
构建Hazelcast Serializer
,这是一种启动命名的Hazelcast嵌入式成员并按名称引用它的方法:
Config config = new Config();
// apart from your config, setup the instance name
config.setInstanceName("jcache-test");
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
// request the server-side caching provider
// same method to bind by instance name also applies to client-side caching provider
CachingProvider cachingProvider = Caching.getCachingProvider(HazelcastCachingProvider.SERVER_CACHING_PROVIDER);
// request the default CacheManager(url = null & ClassLoader = null)
// indicating it should be bound to the named HazelcastInstance
CacheManager cacheManager = cachingProvider.getCacheManager(null, null,
HazelcastCachingProvider.propertiesByInstanceName("jcache-test"));
// use the CacheManager as usual
Cache<String, String> cache = cacheManager.createCache("cache", new MutableConfiguration<>());
cache.put("1", "a");
System.out.println(cache.get("1"));
[有很多方法可以将CacheManager
绑定到显式配置的HazelcastInstance
,您可以查看this reference manual section中的示例。
作为旁注,通常,Hazelcast期望启动时所用的Config
是最终的。 Hazelcast启动后,不考虑对Config
对象的更改,除了可以在启动后添加的特定数据结构配置外,如here所述。