我正在尝试按照本教程构建一个简单的 Rest Web 服务
但是当我在 Eclipse 上运行这个项目时,出现了一个错误:
Mar 11, 2018 8:39:33 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [Distance] in web application [/Distance] threw load() exception
java.lang.IllegalArgumentException
at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:170)
at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:153)
at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:424)
at org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener.process(AnnotationAcceptingListener.java:170)
at org.glassfish.jersey.server.ResourceConfig.scanClasses(ResourceConfig.java:892)
at org.glassfish.jersey.server.ResourceConfig._getClasses(ResourceConfig.java:849)
at org.glassfish.jersey.server.ResourceConfig.getClasses(ResourceConfig.java:755)
at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1181)
at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1154)
at org.glassfish.jersey.server.ResourceConfig.createRuntimeConfig(ResourceConfig.java:1150)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:322)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:315)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1230)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1174)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1066)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5370)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5668)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1700)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1690)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.base/java.lang.Thread.run(Thread.java:844)
有人可以告诉我我错在哪里吗?提前谢谢你。对不起,我的英语不好
在一些开放的依赖项更新到新版本后,我的 Maven 项目中遇到了同样的错误。就我而言,他们是
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>[1.3.2,)</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>[3.0.1,)</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>[2.5.0,)</version>
</dependency>
分别下载
mybatis-spring-2.0.0-SNAPSHOT.jar
mybatis-3.5.0-SNAPSHOT.jar
eclipselink-3.0.0-SNAPSHOT.jar
我在Maven Respository中搜索了JAR的历史记录(通常类似于{user-home}/.m2/repository
(,发现所有JAR在我收到此错误的那天都已更新。
我在pom.xml
中使用"封闭"依赖项恢复了 JAR 的先前版本,即:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>**2.5.0**</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>**1.3.2**</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>**3.4.6**</version>
</dependency>
然后更新依赖项。马文已下载
mybatis-spring-1.3.2.jar
mybatis-3.4.6.jar
eclipselink-2.5.0.jar
相反,一切都很好。
甚至不知道你是否在使用pom.xml(Maven项目(,但当然你正在运行Tomcat,所以检查你的内部是否有一些不兼容或最近修改的jar版本
。{catalina.base}/lib
或您的网络应用
WEB-INF/lib
希望这有帮助。