我有一个servlet应用程序,我部署在Tomcat服务器上。我使用Maven来解析依赖关系,使用Hibernate来进行数据库连接。目前我在运行应用程序时遇到以下问题:
java.lang.ClassNotFoundException: org.dom4j.io.STAXEventReader
我添加了Maven依赖:
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
它出现在部署的WAR文件中,特别是org.dom4j.io.STAXEventReader
可以在装入WAR的jar中找到。然而,我得到了同样的类没有发现异常。我已经花了几天时间在谷歌搜索解决方案,但还没找到任何东西。有没有人面对这样的事情?
在此之前,我遇到了HibernateException
的类似问题,但它消失了(我希望),因为我改变了使用的Hibernate版本(这真的很奇怪!)。
我附上了完整的堆栈跟踪:
SEVERE: Allocate exception for servlet com.prefserver.servlets.DispatcherServlet
java.lang.ClassNotFoundException: org.dom4j.io.STAXEventReader
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43)
at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:124)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:119)
at com.prefserver.dao.PlayerDaoImpl.createSessionFactory(PlayerDaoImpl.java:24)
at com.prefserver.dao.PlayerDaoImpl.<clinit>(PlayerDaoImpl.java:33)
at com.prefserver.utility.RegistrationChecker.<init>(RegistrationChecker.java:17)
at com.prefserver.servlets.DispatcherServlet.<clinit>(DispatcherServlet.java:43)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:116)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:724)
输出 mvn依赖关系:tree -Dverbose -Dincludes = dom4j
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ PrefServer ---
[INFO] com.prefserver:PrefServer:war:0.0.1-SNAPSHOT
[INFO] +- org.hibernate:hibernate-core:jar:5.0.0.Final:compile
[INFO] | \- (dom4j:dom4j:jar:1.6.1:compile - omitted for duplicate)
[INFO] +- org.hibernate:hibernate-entitymanager:jar:5.0.0.Final:compile
[INFO] | \- (dom4j:dom4j:jar:1.6.1:compile - omitted for duplicate)
[INFO] \- dom4j:dom4j:jar:1.6.1:provided (scope not updated to compile