gpt4 book ai didi

java - 无法解析类型 [org.glassfish.jersey.message.filtering.spi.ObjectProvider] 的任何 bean

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:51:36 26 4
gpt4 key购买 nike

尝试将我的 Jersey Web 服务从 Moxy 转移到 Jackson json 媒体提供程序,发现了几个我目前无法解决的问题:

首先,moxy 对于同一段代码工作正常,但是因为我们在其他项目中到处都在使用 jackson,所以我想保持一致......所以我改变了

1) pom中的依赖

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>

2) ResourceConfig注册

register(JacksonFeature.class)

但是当我运行我的 web 服务时我开始遇到这个异常(基本上它发生在我从 web 服务方法返回时):

Caused by: org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308: Unable to resolve any beans for Types: [org.glassfish.jersey.message.filtering.spi.ObjectProvider<com.fasterxml.jackson.databind.ser.FilterProvider>]; Bindings: [QualifierInstance{annotationClass=interface javax.enterprise.inject.Default, values={}, hashCode=48147280}]
at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:815) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:75) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.glassfish.jersey.jackson.internal.FilteringJacksonJaxbJsonProvider.writeTo(FilteringJacksonJaxbJsonProvider.java:130) [jersey-media-json-jackson-2.17.jar:]
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265) [jersey-common-2.17.jar:]
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250) [jersey-common-2.17.jar:]
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) [jersey-common-2.17.jar:]
at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106) [jersey-server-2.17.jar:]
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) [jersey-common-2.17.jar:]
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86) [jersey-server-2.17.jar:]
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) [jersey-common-2.17.jar:]
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1128) [jersey-common-2.17.jar:]
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:664) [jersey-server-2.17.jar:]
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:421) [jersey-server-2.17.jar:]
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:411) [jersey-server-2.17.jar:]
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:308) [jersey-server-2.17.jar:]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [jersey-common-2.17.jar:]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [jersey-common-2.17.jar:]
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [jersey-common-2.17.jar:]
at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [jersey-common-2.17.jar:]
at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [jersey-common-2.17.jar:]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [jersey-common-2.17.jar:]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:288) [jersey-server-2.17.jar:]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1110) [jersey-server-2.17.jar:]
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:401) [jersey-container-servlet-core-2.17.jar:]
... 29 more

是的...显然,如果需要的话,我们会使用 WildFly 作为应用服务器。

因此,如果有人能指出问题出在哪里,那就太棒了。

干杯!

最佳答案

问题似乎出现在 FilteringJacksonJaxbJsonProvider 中,它是 Jersey 自己的 Jackson 提供程序,因为它支持它 Entity Data Filtering .似乎正在进行一些注入(inject)(调用焊接)导致它失败。如果您不需要实体数据过滤功能,您可以去掉 jersey-media-json-jackson 并使用

<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson2.version}</version>
</dependency>
// as of now ${jackson2.version} == 2.5.3

至于 Weld 问题,我不确定它将来是否会给您带来问题,因此我不会考虑将更改 Jackson 依赖项作为解决方案,而是一种变通方法。

您在评论中说您正在使用 gf-cdi。也许这就是问题所在。在 Jersey 2.14 之后不再生产该工件(您使用的是 Jersey 2.17)。 CDI 支持模块已更改。可以看到27.3.1. Release 2.15 Highlights .它提到了一些关于 CDI 支持依赖项的事情。

CDI support improvement caused breaking changes for those users directly referring to the following CDI supporting Jersey module in maven:

<dependency>
<groupId>org.glassfish.jersey.containers.glassfish</groupId>
<artifactId>jersey-gf-cdi</artifactId>
<version>${pre-2.15-version}</version>
</dependency>

The above dependency needs to be replaced with:

<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-cdi1x</artifactId>
<version>2.17</version>
</dependency>

The following needs to be included in addition if you want to leverage CDI JTA support:

<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-cdi1x-transaction</artifactId>
<version>2.17</version>
</dependency>

关于java - 无法解析类型 [org.glassfish.jersey.message.filtering.spi.ObjectProvider<com.fasterxml.jackson.databind.ser.FilterProvider>] 的任何 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30432820/

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