我有一个带有Spring Cache的系统,里面有多个类加载器。实际上我使用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;
}
由于多个类加载器我收到错误,当我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()
,但它是null,当我创建它时,就像Ignite忽略了那里的类。
答案 0 :(得分:1)
我不建议对域模型类使用对等类加载。相反,您应该在所有节点的类路径上提供所有类,并关闭对等类加载(igniteConfiguration.setPeerClassLoadingEnabled(false)
)。
另请注意,从即将发布的Ignite 1.5开始,默认情况下缓存数据将以二进制格式存储,因此即使禁用了对等类加载,也不必在服务器节点上部署类。 / p>