试图从Moxy转移到Jackson json媒体提供商以获取我的Jersey网络服务,并发现了一些我目前无法解决的问题:
首先,moxy在同一段代码中运行良好,但由于我们在其他项目中使用jackson,我希望保持一致... 所以我改变了
1)对pom的依赖
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
2)ResourceConfig regester
register(JacksonFeature.class)
但是当我运行我的webservice时,我开始遇到这个异常(基本上当我从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作为应用服务器,如果重要的话。
因此,如果有人能指出我可能出现问题的地方,那就太棒了。
干杯!
答案 0 :(得分:5)
问题似乎发生在FilteringJacksonJaxbJsonProvider
,这是泽西岛自己的杰克逊提供商,因为它支持它Entity Data Filtering。似乎有一些注入(调用Weld)导致它失败。如果您不需要实体数据过滤功能,则可以删除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
。也许这就是问题所在。在泽西岛2.14(你使用泽西岛2.17)之后不再生成该神器。 CDI支持模块已更改。你可以看到27.3.1. Release 2.15 Highlights。它提到了有关CDI支持依赖的一些事情。
CDI支持改进导致那些用户直接引用以下CDI支持泽西模块maven的重大变更:
<dependency> <groupId>org.glassfish.jersey.containers.glassfish</groupId> <artifactId>jersey-gf-cdi</artifactId> <version>${pre-2.15-version}</version> </dependency>
上述依赖关系需要替换为:
<dependency> <groupId>org.glassfish.jersey.ext.cdi</groupId> <artifactId>jersey-cdi1x</artifactId> <version>2.17</version> </dependency>
如果您想利用CDI JTA支持,还需要包含以下内容:
<dependency> <groupId>org.glassfish.jersey.ext.cdi</groupId> <artifactId>jersey-cdi1x-transaction</artifactId> <version>2.17</version> </dependency>
答案 1 :(得分:0)