有人可以帮助创建一个支持 Ehcache 的 CacheManager
使用 Spring JCacheCacheManager
通过xml?我有这样的东西。不知道如何创建 javax.cache.CacheManager
对于 Ehcache3。
<bean id="myCacheManager"
class="org.springframework.cache.jcache.JCacheCacheManager">
<property name="cacheManager" value="..." />
</bean>
谢谢!
最佳答案
推荐的方法是使用 org.springframework.cache.jcache.JCacheManagerFactoryBean
您可以在其中注入(inject) URI
, Properties
和 ClassLoader
.然后这个工厂 bean 将使用标准的 JCache Caching
创建 javax.cache.CacheManager
的类.
对于 Ehcache,URI
用于指向 ehcache.xml
然后将配置 CacheManager
.
因此扩展您的示例配置:
<bean id="jCacheManager" class="org.springframework.cache.jcache.JCacheManagerFactoryBean">
<property name="cacheManagerUri" value="file://path/to/ehcache.xml"/>
</bean>
<bean id="myCacheManager" class="org.springframework.cache.jcache.JCacheCacheManager">
<property name="cacheManager" ref="jCacheManager" />
</bean>
有关 Ehcache 3/JCache 集成的更多信息,请参阅 the documentation .
关于spring - 在 Spring 4 中使用 ehcache 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42294949/