2

我有一个带有 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.ISOLATEDDeploymentMode.PRIVATE但它们不能使用igniteConfiguration.setPeerClassLoadingEnabled(true),所以我必须手动注册所有类,我没有找到如何使用 LocalDeploymentSpi,我尝试使用igniteConfiguration.getDeploymentSpi()但它为空,当我创建它时就像 Ignite 忽略那里的课程。

4

1 回答 1

1

我不建议对域模型类使用对等类加载。相反,您应该使所有类在所有节点的类路径上可用,并关闭对等类加载 ( igniteConfiguration.setPeerClassLoadingEnabled(false))。

另请注意,从即将发布的 Ignite 1.5 开始,缓存数据将默认以二进制格式存储,因此即使禁用对等类加载,您也不必在服务器节点上部署类。

于 2015-12-02T23:14:07.283 回答