【发布时间】:2015-11-03 19:44:08
【问题描述】:
我正在尝试使用 Spring @Cacheable 和 @Transactional 设置事务性 ehcache。
我的缓存与@Cacheable 一起工作得很好,但是一旦我设置我的缓存以使用本地事务:
<cache name="currencyCodeMaps" maxElementsInMemory="100" overflowToDisk="false" timeToIdleSeconds="5" timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU" transactionalMode="local"/>
当我访问缓存时出现错误:
net.sf.ehcache.transaction.TransactionException: transaction not started
即使相同的方法被注解@Transactional。 我的 Spring 事务管理器是:
org.springframework.orm.jpa.JpaTransactionManager
ehcache documentation 表示本地事务受到明确控制:
本地事务不受事务管理器控制。 取而代之的是一个显式的 API,可以在其中获得对 CacheManager 的 TransactionController 使用 cacheManager.getTransactionController() 和中的步骤 事务被显式调用
但这会很困难,因为我想将我的 ehcache 事务与 DB 事务同步,而 DB 事务由 @Transactional 控制。
有没有办法让本地 Ehcache 事务与 Spring @Transactional 一起工作?
【问题讨论】:
标签: spring transactions ehcache