我在tomcat中运行了一个非常简单的Jersey 2应用程序。它是用maven构建的,maven生成一个war文件。当我在泽西岛2.16时,它运作良好。我有" RELEASE"在我的pom中为依赖版本和我今天重建了哪个获得了Jersey 2.21。转到2.21后出现此错误。我有oracle jdk 8和tomcat 7.0.39
Aug 26, 2015 12:16:26 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet threw load() exception
java.lang.NoSuchMethodError: org.glassfish.hk2.utilities.reflection.ReflectionHelper.resolveField(Ljava/lang/Class;Ljava/lang/reflect/Field;)Ljava/lang/reflect/Type;
at org.jvnet.hk2.internal.Utilities.getFieldInjectees(Utilities.java:1911)
at org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:160)
at org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:179)
at org.jvnet.hk2.internal.SystemDescriptor.internalReify(SystemDescriptor.java:723)
at org.jvnet.hk2.internal.SystemDescriptor.reify(SystemDescriptor.java:678)
at org.jvnet.hk2.internal.ServiceLocatorImpl.reifyDescriptor(ServiceLocatorImpl.java:463)
at org.jvnet.hk2.internal.ServiceLocatorImpl.reifyDescriptor(ServiceLocatorImpl.java:477)
at org.jvnet.hk2.internal.ServiceLocatorImpl.checkConfiguration(ServiceLocatorImpl.java:1620)
at org.jvnet.hk2.internal.ServiceLocatorImpl.addConfiguration(ServiceLocatorImpl.java:2005)
at org.jvnet.hk2.internal.DynamicConfigurationImpl.commit(DynamicConfigurationImpl.java:246)
at org.glassfish.jersey.internal.inject.Injections.bind(Injections.java:156)
at org.glassfish.jersey.internal.inject.Injections._createLocator(Injections.java:144)
at org.glassfish.jersey.internal.inject.Injections.createLocator(Injections.java:123)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:328)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:390)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:362)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5123)
这是我的maven配置:
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
...
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt-spring3</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>${cassandra.driver.version}</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
答案 0 :(得分:2)
对于将来搜索类似例外的人。
对我来说,我必须从2.4.0-b34
中排除旧的jersey-container-servlet
版本的hk2-locator:
compile (group: 'org.glassfish.jersey.containers',
name: 'jersey-container-servlet',
version: '2.23.1') {
exclude group: 'org.glassfish.hk2', module: 'hk2-locator'
}
因为包含了2.4.0-b34
。使用hk2-locator:2.4.0
明确解决了它。
潜在地,对于Jersey / hk2 / Jackson中的所有NoSuchMethodError
,可以通过打印出Maven / Gradle依赖树来匹配Jersey与正确的依赖关系。
答案 1 :(得分:1)
我也遇到过这个问题。在我的情况下,它是由两个版本的Jersey库--2.19和2.21 - 一起使用引起的。
org.glassfish.jersey.containers:jersey-container-servlet:2.19
org.glassfish.jersey.ext:jersey-spring3:2.21