2017-02-10 1 views
0

こんにちは私のプロジェクトはStruts2/Hibernate/Springです。複数のehcache cacheManagerを持つStruts2/Hibernate/Springプロジェクト

  1. 休止5.2.5.Final
  2. Struts2の2.3.31
  3. 我々が使用している春4.3.5.RELEASE
  4. ehcacheを2.10.3

次のバージョンでは アノテーションベースの設定。

@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; 
} 

}

我々はクォーツのcronジョブ経由で呼び出される主な方法があります:

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メソッドが発射されていると、私たちは次のようにehcacheクラスを持っています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に設定しますが、これは起こっています。これを解決するための提案やアイデアはありますか?おかげさまで

答えて

0

あなたのCacheManager()メソッドでCacheManager.newInstance(Configuration configuration)に変更new CacheManager(Configuration configuration)。参照先CacheManager Creation Modes

関連する問題