我正在尝试将 EHCache 的事务能力与 Atomikos 和 Apache Tomcat 一起使用(用于 JMS 和 Hibernate,但这只是为了向怀疑者保证我真的需要 JTA)。
我目前正在研究一个小型 POC,我试图在其中放置一个MyValue
实现的实例,Serializable
当我尝试提交事务时,我以 __ClassNotFoundException
作为根(堆栈跟踪位于末尾)。
当我 jarMyValue
文件并将其放在 %TOMCAT_HOME%\lib 下时,我没有例外。
重要的是要补充一点,因为我在atomikos 教程中看到了Atomikos 的 jar 和 EHCache jar 都在 %TOMCAT_HOME%\lib 下的指令。
这是报价:
当 Atomikos 事务管理器在 Tomcat 中全局安装时,您现在还必须将 JDBC 驱动程序安装在同一全局位置(即:安装到 TOMCAT_HOME/lib 文件夹中)。如果您不这样做,您将在 Web 应用程序部署期间收到 NoClassDefFoundErrors 或 ClassNotFoundException 甚至 ClassCastException。
这不是 Atomikos 或 Tomcat 的限制,而是 Tomcat 和 Atomikos 都必须遵循的 J2EE 类加载设计。
问题是我当然不能在那个文件夹下拥有我所有的值类。
我是否误输入了指令?
有没有人遇到过这个问题?
EHCache.xml
<cache name="myCache"
maxElementsInMemory="1000"
eternal="true"
overflowToDisk="false"
diskPersistent="false"
memoryStoreEvictionPolicy="LRU"
transactionalMode="xa"
/>
堆栈跟踪
net.sf.ehcache.CacheException: When configured copyOnRead or copyOnWrite, a Store will only accept Serializable values
at net.sf.ehcache.store.compound.SerializationCopyStrategy.copy(SerializationCopyStrategy.java:47)
at net.sf.ehcache.store.compound.Segment.potentiallyCopy(Segment.java:176)
at net.sf.ehcache.store.compound.Segment.create(Segment.java:342)
at net.sf.ehcache.store.compound.Segment.put(Segment.java:400)
at net.sf.ehcache.store.compound.CompoundStore.put(CompoundStore.java:132)
at net.sf.ehcache.transaction.StorePutCommand.execute(StorePutCommand.java:43)
at net.sf.ehcache.transaction.xa.VersionAwareWrapper.execute (VersionAwareWrapper.java:68)
at net.sf.ehcache.transaction.xa.EhcacheXAResourceImpl.prepareInternal(EhcacheXAResourceImpl.java:224)
at net.sf.ehcache.transaction.xa.TransactionXARequestProcessor$XARequestCallable.call(TransactionXARequestProcessor.java:150)
at net.sf.ehcache.transaction.xa.TransactionXARequestProcessor$XARequestCallable.call(TransactionXARequestProcessor.java:117)
at net.sf.ehcache.transaction.xa.XAThreadPool$MultiRunner.run(XAThreadPool.java:115)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: com.myCompany.testJTA.MyValue
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:604)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:480)
at net.sf.ehcache.Element.readObject(Element.java:796)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at net.sf.ehcache.store.compound.SerializationCopyStrategy.copy (SerializationCopyStrategy.java:45)
... 16 more