簡體   English   中英

具有多個ehcache cacheManager的Struts2 / Hibernate / Spring項目

[英]Struts2/Hibernate/Spring project with multiple ehcache cacheManager

嗨,我的項目是Struts2 / Hibernate / Spring。 具有以下版本:

  1. 休眠5.2.5。最終版
  2. Struts2的2.3.31
  3. 春季4.3.5。發布
  4. ehCache 2.10.3

我們正在使用基於注釋的配置。 我們有以下ehCache類:

@Configuration
@EnableCaching
public class CacheConfig {

@Bean
public EhCacheCacheManager cacheManager() {
    return new EhCacheCacheManager(ehCacheCacheManager().getObject());
}

@Bean
public EhCacheManagerFactoryBean ehCacheCacheManager() {
    EhCacheManagerFactoryBean cmfb = new EhCacheManagerFactoryBean();
    cmfb.setConfigLocation(new ClassPathResource("ehcache.xml"));
    cmfb.setShared(true);
    cmfb.setAcceptExisting(true);
    return cmfb;
}

}

我們有一個通過Quartz cron job調用的主要方法:

public static void main(String[] args) {
    ApplicationContext context = new AnnotationConfigApplicationContext("com.abc");
    MyJobUtil myJob = new MyJobUtil(context);

    ...our business logic code...

    myJob.destroy(context);
}

問題是,當main方法啟動了Quartz cron作業時,我們運行以下錯誤:

Caused by: net.sf.ehcache.CacheException: Another CacheManager with same name 'oddsCache' already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.

我們已經搜索了論壇,並將EhCacheManagerFactoryBean設置為share = true,但是這種情況正在發生。 有什么建議/想法可以解決這個問題? 謝謝。

在您的cacheManager()方法中,將new CacheManager(Configuration configuration)更改為CacheManager.newInstance(Configuration configuration) 請參考CacheManager創建模式

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM