java - JAX-WS 服务实现类名称自定义不起作用

标签 java web-services maven jax-ws wsimport

我正在使用 Maven 生成 Web 服务的实现代码。最初,此代码是使用其他工具(可能是 Eclipse 中的向导)从 WSDL 和模式生成的。 jaxws-maven-plugin生成的服务实现类名是MyService_MyServieSOAPImpl。最初生成时,实现类被命名为 MyService_SOAPImplementation。我猜测 Eclipse 使用的向导允许用户选择实现类的名称。我尝试使用 sei 元素,但它不起作用。这是我的 POM 中的 wsimport 插件的片段:

<plugin>
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
                <phase>generate-sources</phase>
                <id>generateMyServiceFromWSDL</id>
                <goals>
                    <goal>wsimport</goal>
                </goals>
                <configuration>
                    <genJWS>true</genJWS>
                    <bindingDirectory>${basedir}/src/main/bindings</bindingDirectory>
                    <bindingFiles>
                        <bindingFile>otherSchema.episode</bindingFile>
                    </bindingFiles>
                    <wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
                    <wsdlFiles>
                        <wsdlFile>MyService.wsdl</wsdlFile>
                    </wsdlFiles>
                    <wsdlLocation>${project.basedir}/src/main/resources/wsdl/MyService.wsdl</wsdlLocation>
                    <sourceDestDir>${project.basedir}/src/main/java</sourceDestDir>
                    <sei>com.myCompany.MyService_SOAPImplementation</sei>
                    <xdonotoverwrite>true</xdonotoverwrite>
                    <xnocompile>true</xnocompile>
                    <xdebug>true</xdebug>
                    <verbose>true</verbose>
                    <target>2.0</target>
                </configuration
            </execution>
            ...

从我读过的一些文档来看,sei 似乎只适用于wsgen,不适用于wsimport。如果是这样,是否有任何方法可以强制为实现类名称命名?


更新

好的,根据我的阅读,应该可以使用 JAX-WS 绑定(bind)文件而不是直接在 POM 文件中执行此操作。

我已经这样创建了我的绑定(bind)文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxws:bindings version="2.1" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
                            xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
                            xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                            jaxws:wsdlLocation="src/main/webapp/wsdl/MyService.wsdl">
        <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='MyService']">
            <!-- change the generated SEI class -->
            <jxb:class name="MyServiceSOAPImpl"></jxb:class>
        </jaxws:bindings>
</jaxws:bindings>

但这似乎仍然没有任何效果 - wsimport 仍在生成作为 MyService_MyServiceSOAPImpl 的实现。

最佳答案

尝试改变你的

<jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='MyService']">

<jaxws:bindings node="wsdl:definitions/wsdl:service[@name='MyServiceService']">

请注意,节点路径的第二部分是service 而不是portType。您将使用 portType 来自定义服务接口(interface),而不是实现

顺便说一句,重要的是要注意 JAX-WS 绑定(bind)(表面上)需要在它们自己的 XML 文件中(根据 WSDL)并且不包含在 JAXB 绑定(bind)中。

有人可能会发现这里的 JAX-WS 绑定(bind)列表很有用:http://docs.oracle.com/cd/E13222_01/wls/docs103/webserv/data_types.html#wp227312

关于java - JAX-WS 服务实现类名称自定义不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21999041/

相关文章:

java - 数据库构建后运行数据脚本

java - 继承强制编译错误

java - 部署网络服务

javascript - 在 Angular JS 的 uri 参数中使用 'slash' 字符使用 Restful 服务

java - 如何在 Java 7 中启用 TLSv1.2?

java - 带有打包依赖项的 Maven 构建 jar

java - 用 Java 构建处理数据库的软件

java - 通过前台监听器调用后台布局监听器

html - 防止其他人调用您的 JSON 网络服务

maven - IntelliJ新项目-maven原型(prototype)列表为空