JAX-WS = 安装 Apache CXF 后,它“窃取"了默认JDK JAX-WS实现,如何解决? [英] JAX-WS = When Apache CXF is installed it "steals" default JDK JAX-WS implementation, how to solve?

查看:29
本文介绍了JAX-WS = 安装 Apache CXF 后,它“窃取"了默认JDK JAX-WS实现,如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题.

  1. 使用 wsimport,我从 WSDL(在一个专用的 eclipse java 项目中)生成了 als JAX-WS 代码.这在 JDK6 中运行良好,无需任何外部依赖(在 Eclipse 中运行)

  1. Using wsimport I generated als JAX-WS Code from a WSDL (in a dedicated eclipse java project). This works fine in JDK6 without any external dependencies (running in Eclipse)

我有第二个项目,我曾经在其中使用过 Apache CXF.如果我将 1.) 中描述的代码复制到这个项目中,突然间不是 JDK 执行 JAX-WS 东西(我生成的文件),而是 Apache CXF.

I have second project where I once used Apache CXF. If I copy the Code described in 1.) into this project, suddenly not the JDK executes the JAX-WS stuff (files I generated), but rather Apache CXF.

如何防止 Apache CXF运行"JAX-WS 的东西.(问题是,CXF 无法运行代码...).我也完全不明白 Apache CXF 如何发现这些类.我没有注册他们吗?

How can I prevent Apache CXF "running" the JAX-WS stuff. (Problem is, CXF Fails to run the code...). I also completely do not understand how Apache CXF discovers these classes. I did not register them anywere?

非常感谢!马库斯

推荐答案

Apache CXF(准确地说是cxf-rt-frontend-jaxws-*.jar)将自己注册为 JAX-WS 提供者在 JVM 中.在前面提到的 JAR 中有一个名为:/META-INF/services/javax.xml.ws.spi.Provider 的文件,内容如下:

Apache CXF (cxf-rt-frontend-jaxws-*.jar to be precise) registers itself as a JAX-WS provider in the JVM. Inside the aforementioned JAR there is a file named: /META-INF/services/javax.xml.ws.spi.Provider with the following contents:

org.apache.cxf.jaxws.spi.ProviderImpl

如果您现在查看 javax.xml.ws.spi.FactoryFinder#find 方法,您会发现 JDK 在 CLASSPATH 中搜索 javax.xml.ws.spi 的存在.Provider 文件,如果不可用,则回退到默认的 Sun 实现.因此,您有两个选项可以强制回退:

If you now look at javax.xml.ws.spi.FactoryFinder#find method you will discover that JDK searches the CLASSPATH for the presence of javax.xml.ws.spi.Provider file and falls back to default Sun implementation if not available. So you have two options to force fallback:

  • 要么从 CLASSPATH 中删除 cxf-rt-frontend-jaxws-*.jar

或覆盖 CXF 提供的 javax.xml.ws.spi.Provider 文件以指向回退位置

or override javax.xml.ws.spi.Provider file provided by CXF to point to fallback location

第二个选项实际上更容易一些.只需创建:

The second option is actually a bit easier. Simply create:

/src/main/resources/META-INF/services/javax.xml.ws.spi.Provider

文件(假设您使用的是 Maven),其内容如下:

file (assuming you are using Maven) with the following contents:

org.apache.cxf.jaxws.spi.ProviderImpl

就是这样,用 javax.xml.ws.Endpoint#publish 测试.

That's it, tested with javax.xml.ws.Endpoint#publish.

这篇关于JAX-WS = 安装 Apache CXF 后,它“窃取"了默认JDK JAX-WS实现,如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆