根据Ehcache documentation ,从2.0版本开始,Ehcache缓存可能会参与JTA基于属性值的交易transactionalMode
在元素 <cache/>
.
如果这是真的,那么为什么Ehcache在我的Ehcache配置文件中遇到这个属性时,会抛出以下异常并提示“Element does not allowed attribute ‘transactionalMode’.”:
Caused by: net.sf.ehcache.CacheException: Error configuring from zip:C:/Program Files/Oracle/Middleware/user_projects/domains/abstrack1/servers/AdminServer/tmp/_WL_user/_appsdir_middleware-ear-1.0-SNAPSHOT_ear/n8rga7/middleware-ejb-1.0-SNAPSHOT.jar!/ehcache.xml. Initial cause was Error configuring from input stream. Initial cause was null:35: Element <cache> does not allow attribute "transactionalMode".
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:95)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:131)
at net.sf.ehcache.CacheManager.parseConfiguration(CacheManager.java:241)
at net.sf.ehcache.CacheManager.init(CacheManager.java:190)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:183)
at net.sf.ehcache.hibernate.EhCacheProvider.start(EhCacheProvider.java:128)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:183)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 76 more]]>
这是我的 ehcache.xml
中的示例缓存定义我在其中设置了 transactionalMode
的文件至“xa”:
<cache
name="com.db.spgit.abstrack.model.Security"
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="86400"
overflowToDisk="false"
transactionalMode="xa" />
最佳答案
事实证明,Maven 还包含了 Ehcache 1.2.3在我的项目 EAR 文件中,因为 Hibernate Ehcache Integration 3.3.2.GA需要Ehcache 1.2.3。
关于configuration - Ehcache 元素 <cache/> 不允许属性 "transactionalMode"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3560659/