0

在 osgi/aem 中遇到集群 ehcache 问题。只有第一个项目构建/安装它工作正常,但第二个构建/安装它停止工作,产生很多错误。看起来 terracotta 连接、cachemanager 或第三个东西没有正确关闭。

即使在删除捆绑包后,它也会尝试连接到 terracotta。

好的日志,日志中的错误

我在 osgi 中将 ehcache 和 ehcache-clustered 作为独立包安装。还尝试将它们嵌入我的包中。Ehcache 和 ehcache-clustered 设置为依赖项,也尝试使用 org.apache.servicemix.bundles.javax-cache-api (嵌入,不确定是否需要)

第一次所有 ehcache 和 ehcache 集群服务都处于活动状态,第二次满意。

Ehcache 包ehcache 集群包javax-cache-api 包我的项目包

pom.xml

我厌倦了作为独立 java 应用程序的相同代码,它工作得非常好(https://github.com/ehcache/ehcache3-samples/blob/master/clustered/src/main/java/org/ehcache/sample/ClusteredXML.java )

所以不确定我错过了什么(依赖项,导入包..)?

ehcache 配置兵马俑配置

@Activate
private void activate() {
    LOGGER.info("Creating clustered cache manager from XML");

    URL myUrl = ClusteredService.class.getResource("/com/myco/services/ehcache-clustered-local2.xml");
    Configuration xmlConfig = new XmlConfiguration(myUrl);

    try (CacheManager cacheManager = CacheManagerBuilder.newCacheManager(xmlConfig) ) {
        cacheManager.init();

        org.ehcache.Cache<String, String> basicCache = cacheManager.getCache("basicCache4", String.class, String.class);

        LOGGER.info("1. Putting to cache");
        basicCache.put("1","abc");

        LOGGER.info("1. Getting from cache");
        String value = basicCache.get("1");
        LOGGER.info("1. Retrieved '{}'", value);

        LOGGER.info("cache manager status2, " + cacheManager.getStatus().toString());

    }
}
4

1 回答 1

0

You have to also create a @Deactivate method where you do a cacheManager.shutdown();

I guess if you call your code in a non OSGi project twice you would also experience the same error.

于 2019-06-24T08:52:24.900 回答