gpt4 book ai didi

java - ClassNotFoundException 与 EHCache-Atomikos

转载 作者:行者123 更新时间:2023-11-30 11:56:56 24 4
gpt4 key购买 nike

我正在尝试将 EHCache 的事务处理能力与 Atomikos 和 Apache Tomcat 一起使用(与 JMS 和 Hibernate 一起使用,但这只是为了向怀疑论者保证我真的需要 JTA)。

我目前正在开发一个小型 POC,我试图在其中放置一个实现 SerializableMyValue 实例,当我尝试提交事务时,我得到以 ClassNotFoundException 作为根的 __(堆栈跟踪在末尾)。

当我压缩 MyValue 文件并将其放在 %TOMCAT_HOME%\lib 下时,我没有发现异常。

根据我在 atomikos tutorial 上看到的说明,添加这一点很重要Atomikos 的 jar 和 EHCache 的 jar 都在 %TOMCAT_HOME%\lib 下。

这是引述:

When the Atomikos transaction manager is installed globally in Tomcat, you now must also install your JDBC driver at the same global location (ie: into the TOMCAT_HOME/lib folder). If you don't do that, you will get a NoClassDefFoundErrors or a ClassNotFoundException or even a ClassCastException during your web application deployment.
This is not a limitation of Atomikos nor of Tomcat but of the J2EE class loading design that both Tomcat and Atomikos must follow.

当然,问题是我不能将所有值类都放在该文件夹下。

我输入错误的指令了吗?

有人遇到过这个问题吗?

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

最佳答案

It's important to add that due to an instruction I saw on the atomikos tutorial both Atomikos's jars and EHCache jars are under %TOMCAT_HOME%\lib

来自 Web 应用程序的类(即由 WebappX 类加载器加载的类)在 Common 中不可见> 类加载器(参见 Apache Tomcat 6.0 - Class Loader HOW-TO ),这就是您获得 CNFE 的原因。

现在的问题是,为什么要将 EHCache JAR 放在Common 类加载器中?我认为你不需要。在您的 Web 应用程序级别对其进行打包。

引用资料

关于java - ClassNotFoundException 与 EHCache-Atomikos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4098671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com