ehcache / ehcache-jcache

The Ehcache 2.x implementation of JSR107 (JCACHE)
Other
91 stars 48 forks source link

Could not create a cache named "default" through the JSR-107 API #35

Closed snicoll closed 9 years ago

snicoll commented 9 years ago

I am trying to use a region named default using ehcache-jcache. When I tries to create it using the standard JSR-107 API, I get the following exception:

Caused by: net.sf.ehcache.ObjectExistsException: The Default Cache has already been configured
    at net.sf.ehcache.config.Configuration.addCache(Configuration.java:967) ~[ehcache-2.8.3.jar:2.8.3]
    at net.sf.ehcache.config.CacheConfiguration.registerCacheConfiguration(CacheConfiguration.java:1875) ~[ehcache-2.8.3.jar:2.8.3]
    at net.sf.ehcache.config.CacheConfiguration.setupFor(CacheConfiguration.java:1703) ~[ehcache-2.8.3.jar:2.8.3]
    at net.sf.ehcache.config.CacheConfiguration.setupFor(CacheConfiguration.java:1678) ~[ehcache-2.8.3.jar:2.8.3]
    at net.sf.ehcache.CacheManager.initializeEhcache(CacheManager.java:1328) ~[ehcache-2.8.3.jar:2.8.3]
    at net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:1399) ~[ehcache-2.8.3.jar:2.8.3]
    at net.sf.ehcache.CacheManager.addCacheIfAbsent(CacheManager.java:1916) ~[ehcache-2.8.3.jar:2.8.3]
    at org.ehcache.jcache.JCacheManager.createCache(JCacheManager.java:108) ~[jcache-1.0.0.jar:na]

When I only try to access it (i.e. without creating it myself), I get:

java.lang.IllegalArgumentException: Cannot find cache named 'default' for CacheResultOperation[CacheMethodDetails[method=public java.lang.String demo.FooServiceImpl.defaultGet(long), cacheAnnotation=@javax.cache.annotation.CacheResult(cacheKeyGenerator=interface javax.cache.annotation.CacheKeyGenerator, cacheName=default, cachedExceptions=[], skipGet=false, cacheResolverFactory=interface javax.cache.annotation.CacheResolverFactory, exceptionCacheName=, nonCachedExceptions=[]), cacheName='default']]
    at org.springframework.cache.interceptor.AbstractCacheResolver.resolveCaches(AbstractCacheResolver.java:81)
    at org.springframework.cache.jcache.interceptor.AbstractCacheInterceptor.resolveCache(AbstractCacheInterceptor.java:61)
    at org.springframework.cache.jcache.interceptor.CacheResultInterceptor.invoke(CacheResultInterceptor.java:49)
    at org.springframework.cache.jcache.interceptor.JCacheAspectSupport.execute(JCacheAspectSupport.java:131)
    at org.springframework.cache.jcache.interceptor.JCacheAspectSupport.execute(JCacheAspectSupport.java:102)
    at org.springframework.cache.jcache.interceptor.JCacheInterceptor.invoke(JCacheInterceptor.java:61)

Sample project available here

alexsnaps commented 9 years ago

Hey Stéphane, I'll have a look, I probably have a clue already about what's going on, as Ehcache has been considering a Cache named default as a somewhat special case... So probably a legit bug. I'll update this as soon as I know more. Thanks a lot for the reproducible test case btw! Alex

alexsnaps commented 9 years ago

It's an issue in Ehcache-core, raised: https://jira.terracotta.org/jira/browse/EHC-1091