使用 JAX-RS 的 CXF 和 Google Guice + JAX-WS
我想将 CXF 与 Google Guice 集成。我已经在我的项目中使用 Guice,并且我想避免添加额外的依赖项。
我选择 CXF,因为要求之一是能够向服务用户提供 XML、JSON、JSONP 和 SOAP 接口,而无需重复代码(现在我们有 SOAP 特定的类,对于 XML,我们使用 Struts,对于JSON我们写了自己的解析器,我知道,我也觉得很脏)。
无论如何,afaik,CXF 可以满足这个要求,所以看来我被 CXF 困住了。
关于如何将 Guice 与 CXF 集成的任何想法、指示或建议?我想过扩展 CXFNonSpringJaxrsServlet 类并将 Guice 融入其中,但不知怎的,我似乎正在做别人已经做过的事情。
I would like to integrate CXF with Google Guice. I am already using Guice in my project and I want to avoid adding extra dependencies.
CXF was my choice because one of the requirements is to be able to provide XML, JSON, JSONP and SOAP interface to the users of the services without having duplicate code (right now we have SOAP-specific classes, for XML we use Struts and for JSON we wrote our own parsers, I know, I feel dirty too).
Anyway, afaik, CXF can fulfill this requirement, so it seems I'm stuck with CXF.
Any ideas or pointers or advice on how to integrate Guice with CXF? I thought of extending the CXFNonSpringJaxrsServlet
class and hack Guice into it, but it somehow seems like I would be doing something that someone else has already done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 CXF 2.4.x 中,CXF 不再使用 Spring 进行内部配置。因此,没有 Spring,您几乎可以做任何事情。
配置部分绝对是一个问题。然而,所有 Spring 配置内容只是 CXF API 的薄包装。因此,您可以通过 API 配置几乎所有内容。您可能只需要再挖掘一点。
例如,在 CXF 2.4 中,我们现在开始支持在 OSGi 中使用 Blueprint 而不是 Spring。蓝图支持不需要任何 Spring 的东西,而是根据它建模的。
With CXF 2.4.x, CXF no longer uses Spring to internally configure itself. Thus, you can do pretty much anything without Spring.
The configuration parts are definitely an issue. However, all the spring configuration stuff is just thin wrappers over the CXF API's. Thus, you can configure pretty much everything via the API's. You may just need to dig a little bit more.
As an example, with CXF 2.4, we now have started to support using Blueprint instead of Spring in OSGi. The blueprint support doesn't require any of the Spring stuff, but is modelled from it.
这是我一直在使用的(cxf-2.5.0)。
Here is what I have been using (cxf-2.5.0).
你有问题了。 CXF 完全依赖于 Spring,因为它是由 Spring 内部配置的,并且相当广泛地使用了 Spring 的设施。因此,我认为尝试从 Spring 中获取 CXF 以便您可以使用 Guice 是不切实际的;至少,您必须使用自定义 Guice 提供程序复制所有配置,但它仍然无法工作(CXF 的某些部分使用 Spring 的 Web 层)。
您可以尝试在代码中使用 Spring 的 JavaConfig 样式。这大部分与 Guice 所做的事情类似(据我所知)。或者我想你可以尝试在同一个应用程序中使用两个单独的 DI 框架......尽管对我来说这感觉像是一个“搞笑”失败的机会。
You've got a problem. CXF is thoroughly dependent on Spring, due to it being internally configured by Spring and using Spring's facilities quite extensively. As such, I don't think it's practical to try to prise CXF out of Spring just so you can use Guice instead; at a minimum, you'd have to replicate all the configuration with custom Guice providers and it still will not work (parts of CXF use some of Spring's Web layer).
You could try using Spring's JavaConfig style for your code instead. That's mostly similar to the sorts of things that Guice does (as far as I can see). Or I suppose you could try using two separate DI frameworks in the same app… though that feels to me like an opportunity for “hilarious” failure.