I may also be missing something more fundamental. When running unit tests I find that
Eh107CacheManager doesn’t contain
any of my configured caches, even though I have
ehcache.xml available under
src/main/resources and my main application class is annotated with
@EnableCaching. My current cache configuration is below:
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd">
<persistence directory="${java.io.tmpdir}"/>
<cache-template name="cacheDefaults">
<key-type>com.activeos.cache.ActiveOSCacheKey</key-type>
<value-type>java.io.Serializable</value-type>
<expiry>
<tti unit="seconds">300</tti>
</expiry>
<resources>
<heap unit="MB">150</heap>
<disk unit="entries">1000</disk>
</resources>
<jsr107:mbeans enable-management="false" enable-statistics="true"/>
</cache-template>
<cache alias="defaultCache" uses-template="cacheDefaults">
<resources>
<heap unit="MB">10</heap>
</resources>
</cache>
<cache alias="stats" uses-template="cacheDefaults">
</cache>
<cache alias="bar" uses-template="cacheDefaults">
</cache>
<cache alias="foo" uses-template="cacheDefaults">
</cache>
</config> The code is looking for the cache with:
import javax.cache.*;
…
@Autowired
CacheManager cacheManager;
private Cache<CacheKey, Serializable> getCache(String cacheName) {
Cache<CacheKey, Serializable> cache =
cacheManager.getCache(cacheName,
CacheKey.class, Serializable.class);
if (cache == null) {
throw new CacheException(String.format(
"Can't find %s cache!", cacheName));
} else {
return cache;
}
}