gpt4 book ai didi

java - 带 Jersey 的 HK2 注入(inject)管理器,使用 OpenJDK 11 升级

转载 作者:行者123 更新时间:2023-12-02 05:40:49 25 4
gpt4 key购买 nike

当我升级 jdk11 和 jersey 时遇到了一些错误,但这个错误尤其难倒。所以 jersey 2.28 应该与 OpenJDK11 兼容,并修复了之前 2.25.1 中的一些问题,所以我升级了它

我也已经看到了这个,这不是一个有效的解决方案 - Jersey Spring Maven java.lang.NoClassDefFoundError: org/glassfish/jersey/hk2/HK2InjectionManager

在我的 gradle 构建中,此任务失败:

> 任务:ods-impl:测试失败

根据我的任务,这里是依赖项列表

    compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet', version: '2.28'
compile group: 'org.glassfish.jersey.ext', name: 'jersey-spring3', version: '2.26-b03'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: '2.28'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-multipart', version: '2.28'
compile group: 'commons-lang', name: 'commons-lang', version: property('rev.commons-lang')

然后我遇到了一个新错误

java.lang.NoClassDefFoundError: org/glassfish/jersey/hk2/HK2InjectionManager

at org.glassfish.jersey.server.spring.SpringComponentProvider.initialize(SpringComponentProvider.java:112)
at org.glassfish.jersey.server.ComponentProviderConfigurator.lambda$null$0(ComponentProviderConfigurator.java:55)
at java.base/java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:441)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
at org.glassfish.jersey.server.ComponentProviderConfigurator.lambda$init$1(ComponentProviderConfigurator.java:56)
at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:317)
at org.glassfish.jersey.server.ResourceModelConfigurator.bindProvidersAndResources(ResourceModelConfigurator.java:111)
at org.glassfish.jersey.server.ResourceModelConfigurator.init(ResourceModelConfigurator.java:63)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:341)
at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:232)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:291)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:258)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:245)
at org.glassfish.jersey.jetty.JettyHttpContainer.<init>(JettyHttpContainer.java:445)
at org.glassfish.jersey.jetty.JettyHttpContainerProvider.createContainer(JettyHttpContainerProvider.java:37)
at org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:58)
at org.glassfish.jersey.jetty.JettyHttpContainerFactory.createServer(JettyHttpContainerFactory.java:135)
at org.glassfish.jersey.test.jetty.JettyTestContainerFactory$JettyTestContainer.<init>(JettyTestContainerFactory.java:68)
at org.glassfish.jersey.test.jetty.JettyTestContainerFactory$JettyTestContainer.<init>(JettyTestContainerFactory.java:45)
at org.glassfish.jersey.test.jetty.JettyTestContainerFactory.create(JettyTestContainerFactory.java:126)
at org.glassfish.jersey.test.JerseyTest.createTestContainer(JerseyTest.java:254)
at org.glassfish.jersey.test.JerseyTest.setUp(JerseyTest.java:584)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.hk2.HK2InjectionManager
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 54 more

所以我添加了这个依赖项:

compile group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.28'

但是,我仍然遇到相同的错误消息,依赖项匹配方式是否有问题?我看到它在 IntelliJ 中解决了 hk2

enter image description here

进一步挖掘,我注意到 SpringComponentProvider 上的 HK2InjectionManager 是从错误的路径导入的,而不是从 HK2 依赖项的位置导入的

从 Jersey 出发的正确路径:导入 org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;

从 Spring 开始的路径:导入 org.glassfish.jersey.hk2.HK2InjectionManager;

最佳答案

事实证明 jersey-spring3 已经过时了。如果您想将 2.27+ Jersey 与 Spring 一起使用,但更改依赖项以使用 jersey-spring4

编译组:'org.glassfish.jersey.ext',名称:'jersey-spring4',版本:'2.28'

关于java - 带 Jersey 的 HK2 注入(inject)管理器,使用 OpenJDK 11 升级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56139535/

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