gpt4 book ai didi

java - 升级到 jersey 2.21 后,Jersey/Tomcat 应用程序不会为 ReflectionHelper.resolveField 抛出此类方法

转载 作者:行者123 更新时间:2023-11-28 22:37:12 25 4
gpt4 key购买 nike

我有一个在 tomcat 中运行的非常简单的 Jersey 2 应用程序。它是用 maven 构建的,maven 会生成一个 war 文件。当我使用 Jersey 2.16 时,它运行良好。我的 pom 中有依赖版本的“RELEASE”,今天我重建了 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>

最佳答案

供日后搜索类似异常的人使用。

对我来说,我不得不从 jersey-container-servlet 中排除旧的 2.4.0-b34 版本的 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 与正确的依赖关系。

关于java - 升级到 jersey 2.21 后,Jersey/Tomcat 应用程序不会为 ReflectionHelper.resolveField 抛出此类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32235072/

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