我试图从Moxy转移到杰克逊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 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作为应用程序服务器,如果它很重要.
因此,如果有人能够指出我可能存在的问题,那就太棒了.
干杯!
解决方法
问题似乎发生在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 support improvement caused breaking changes for those users directly referring to the following CDI supporting Jersey module in maven:
06001
The above dependency needs to be replaced with:
06002
The following needs to be included in addition if you want to leverage CDI JTA support:
06003