Ignite 和 Spring 多个 Class 装载机
Ignite and Spring with multiple Class Loaders
我有一个带有 Spring 缓存的系统,其中有多个 Class 加载程序。实际上我用的是 ehcache,它工作正常:
@Component
public class ObjectRepository extends MongoRepository<Object> {
// -------------------------- OTHER METHODS --------------------------
@Override
@Cacheable(value = "object", key = "#p0+#p1.name")
public Object get(String id, Class<? extends Object> clazz) {
return super.get(id, clazz);
}
@Override
@CacheEvict(value = "object", key = "#p0+#p1.name")
public void remove(String id, Class<? extends Object> clazz) {
super.remove(id, clazz);
}
@Override
@CacheEvict(value = "object", key = "#p0+#p0.class.name")
public void save(Object object) {
super.save(object);
}
}
我正在尝试更改为点燃:
@Bean
@SuppressWarnings("unchecked")
public CacheManager cacheManager() {
SpringCacheManager springCacheManager = new SpringCacheManager();
IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
igniteConfiguration.setPeerClassLoadingEnabled(true);
igniteConfiguration.setIncludeEventTypes(org.apache.ignite.events.EventType.EVTS_TASK_EXECUTION);
springCacheManager.setConfiguration(igniteConfiguration);
return springCacheManager;
}
因为有多个 Class 加载器,我收到错误消息,当我执行 objectRepository.get("1", com.test.ClassInClassLoader1.class)
时工作正常,但在我执行 objectRepository.get("2", com.test.ClassInClassLoader2.class)
之后我收到错误:
Caused by: class org.apache.ignite.IgniteCheckedException: Encountered incompatible class loaders for cache [class1=com.test.ClassInClassLoader2, class2=com.test.ClassInClassLoader1]
at org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager.registerClass(GridCacheDeploymentManager.java:656)
at org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager.registerClass(GridCacheDeploymentManager.java:601)
at org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager.registerClass(GridCacheDeploymentManager.java:590)
at org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager.registerClasses(GridCacheDeploymentManager.java:573)
at org.apache.ignite.internal.processors.cache.GridCacheUtils.marshal(GridCacheUtils.java:950)
at org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl.marshal(IgniteCacheObjectProcessorImpl.java:94)
at org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl.marshal(CacheObjectPortableProcessorImpl.java:727)
at org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl$UserCacheObjectImpl.prepareForCache(IgniteCacheObjectProcessorImpl.java:343)
... 186 more
我尝试使用 DeploymentMode.ISOLATED
和 DeploymentMode.PRIVATE
但它们不适用于 igniteConfiguration.setPeerClassLoadingEnabled(true)
,所以我必须手动注册所有 类 但我没有找到如何使用 LocalDeploymentSpi 做到这一点,我尝试使用 igniteConfiguration.getDeploymentSpi()
但它为空,当我创建它时就像 Ignite 忽略了那里的 类。
我不建议为域模型 classes 使用对等 class 加载。相反,您应该使所有 classes 在所有节点的 class 路径上可用,并切换对等点 class 加载(igniteConfiguration.setPeerClassLoadingEnabled(false)
)。
另请注意,从即将发布的 Ignite 1.5 开始,缓存数据将默认以二进制格式存储,因此您不必在服务器节点上部署 classes,即使对等 class 加载已禁用。
我有一个带有 Spring 缓存的系统,其中有多个 Class 加载程序。实际上我用的是 ehcache,它工作正常:
@Component
public class ObjectRepository extends MongoRepository<Object> {
// -------------------------- OTHER METHODS --------------------------
@Override
@Cacheable(value = "object", key = "#p0+#p1.name")
public Object get(String id, Class<? extends Object> clazz) {
return super.get(id, clazz);
}
@Override
@CacheEvict(value = "object", key = "#p0+#p1.name")
public void remove(String id, Class<? extends Object> clazz) {
super.remove(id, clazz);
}
@Override
@CacheEvict(value = "object", key = "#p0+#p0.class.name")
public void save(Object object) {
super.save(object);
}
}
我正在尝试更改为点燃:
@Bean
@SuppressWarnings("unchecked")
public CacheManager cacheManager() {
SpringCacheManager springCacheManager = new SpringCacheManager();
IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
igniteConfiguration.setPeerClassLoadingEnabled(true);
igniteConfiguration.setIncludeEventTypes(org.apache.ignite.events.EventType.EVTS_TASK_EXECUTION);
springCacheManager.setConfiguration(igniteConfiguration);
return springCacheManager;
}
因为有多个 Class 加载器,我收到错误消息,当我执行 objectRepository.get("1", com.test.ClassInClassLoader1.class)
时工作正常,但在我执行 objectRepository.get("2", com.test.ClassInClassLoader2.class)
之后我收到错误:
Caused by: class org.apache.ignite.IgniteCheckedException: Encountered incompatible class loaders for cache [class1=com.test.ClassInClassLoader2, class2=com.test.ClassInClassLoader1]
at org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager.registerClass(GridCacheDeploymentManager.java:656)
at org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager.registerClass(GridCacheDeploymentManager.java:601)
at org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager.registerClass(GridCacheDeploymentManager.java:590)
at org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager.registerClasses(GridCacheDeploymentManager.java:573)
at org.apache.ignite.internal.processors.cache.GridCacheUtils.marshal(GridCacheUtils.java:950)
at org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl.marshal(IgniteCacheObjectProcessorImpl.java:94)
at org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl.marshal(CacheObjectPortableProcessorImpl.java:727)
at org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl$UserCacheObjectImpl.prepareForCache(IgniteCacheObjectProcessorImpl.java:343)
... 186 more
我尝试使用 DeploymentMode.ISOLATED
和 DeploymentMode.PRIVATE
但它们不适用于 igniteConfiguration.setPeerClassLoadingEnabled(true)
,所以我必须手动注册所有 类 但我没有找到如何使用 LocalDeploymentSpi 做到这一点,我尝试使用 igniteConfiguration.getDeploymentSpi()
但它为空,当我创建它时就像 Ignite 忽略了那里的 类。
我不建议为域模型 classes 使用对等 class 加载。相反,您应该使所有 classes 在所有节点的 class 路径上可用,并切换对等点 class 加载(igniteConfiguration.setPeerClassLoadingEnabled(false)
)。
另请注意,从即将发布的 Ignite 1.5 开始,缓存数据将默认以二进制格式存储,因此您不必在服务器节点上部署 classes,即使对等 class 加载已禁用。