1

我有两个用于不同服务的 WSDL 文件。两种服务都可以独立工作,但是如果我在同一个 eclipse 项目中包含这两种服务,我会收到以下错误的几个实例:

There's no ObjectFactory with an @XmlElementDecl for the element {http://schemas.foobar.com/oms/2010/10/Models}City.
    this problem is related to the following location:
        at protected javax.xml.bind.JAXBElement com.foobar.schemas.oms._2010._10.models.BusinessUnitData.city
        at com.foobar.schemas.oms._2010._10.models.BusinessUnitData
        at protected com.foobar.schemas.oms._2010._10.models.BusinessUnitData com.foobar.schemas.oms._2010._10.businessunit.CreateBusinessUnitRequest.businessUnitData
        at com.foobar.schemas.oms._2010._10.businessunit.CreateBusinessUnitRequest
        at @javax.xml.bind.annotation.XmlSeeAlso(value=[class com.foobar.schemas.oms._2010._10.businessunit.CreateBusinessUnitRequest])
        at public com.foobar.schemas.oms._2010._10.businessunit.CCreateBusinessUnitRequest com.foobar.schemas.oms._2010._10.businessunit.ObjectFactory.createCCreateBusinessUnitRequest()
        at com.foobar.schemas.oms._2010._10.businessunit.ObjectFactory
        at protected javax.xml.bind.JAXBElement com.foobar.schemas.oms._2010._10.businessunit.AddToStructureRequest.unitStructureData
        at com.foobar.schemas.oms._2010._10.businessunit.AddToStructureRequest
        at @javax.xml.bind.annotation.XmlSeeAlso(value=[class com.foobar.schemas.oms._2010._10.businessunit.AddToStructureRequest])
There's no ObjectFactory with an @XmlElementDecl for the element {http://schemas.foobar.com/oms/2010/10/Models}ClientKey.
    this problem is related to the following location:
        at protected javax.xml.bind.JAXBElement com.foobar.schemas.oms._2010._10.models.BusinessUnitData.clientKey
        at com.foobar.schemas.oms._2010._10.models.BusinessUnitData
        at protected com.foobar.schemas.oms._2010._10.models.BusinessUnitData com.foobar.schemas.oms._2010._10.businessunit.CreateBusinessUnitRequest.businessUnitData
        at com.foobar.schemas.oms._2010._10.businessunit.CreateBusinessUnitRequest
        at @javax.xml.bind.annotation.XmlSeeAlso(value=[class com.foobar.schemas.oms._2010._10.businessunit.CreateBusinessUnitRequest])
        at public com.foobar.schemas.oms._2010._10.businessunit.CCreateBusinessUnitRequest com.foobar.schemas.oms._2010._10.businessunit.ObjectFactory.createCCreateBusinessUnitRequest()
        at com.foobar.schemas.oms._2010._10.businessunit.ObjectFactory
        at protected javax.xml.bind.JAXBElement com.foobar.schemas.oms._2010._10.businessunit.AddToStructureRequest.unitStructureData
        at com.foobar.schemas.oms._2010._10.businessunit.AddToStructureRequest
        at @javax.xml.bind.annotation.XmlSeeAlso(value=[class com.foobar.schemas.oms._2010._10.businessunit.AddToStructureRequest])

这些错误完全填满了我的终端窗口,所以我不知道这种情况发生了多少次。

我正在以两种方式之一生成存根代码。首先,我尝试使用 wsdl2java 生成两者,然后将编译后的代码打包到一个 jar 中,并将其包含在我的构建路径中。我还尝试使用 cxf code-gen 插件创建一个新的 maven 项目。然后我运行“mvn install”并将生成的代码作为 maven 依赖项包含在内。两种技术产生相同的结果。每项服务都可以独立运行。但如果两者都包含在项目中,我会收到对象工厂错误。

是什么导致了这种类型的错误?可以用 jaxb 绑定文件修复吗?如果是这样,我是 web 服务的新手,并且一直无法找到示例绑定文件来学习如何格式化它。

4

2 回答 2

1

使用这个 maven 插件从 WSDL 生成类:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>2.7.1</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-bindings-soap</artifactId>
            <version>2.7.1</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>generate-jaxb</id>
            <phase>generate-sources</phase>
            <configuration>
                <additionalJvmArgs>-Dfile.encoding=UTF8</additionalJvmArgs>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>src/main/webapp/WEB-INF/wsdl/YourWSDL1.wsdl</wsdl>
                        <extraargs>
                            <extraarg>-wsdlLocation</extraarg>
                            <extraarg></extraarg>
                            <extraarg>-client</extraarg>
                            <extraarg>-p</extraarg>
                            <extraarg>your.app.pkg1</extraarg>
                        </extraargs>
                    </wsdlOption>
                    <wsdlOption>
                        <wsdl>src/main/webapp/WEB-INF/wsdl/YourWSDL2.wsdl</wsdl>
                        <extraargs>
                            <extraarg>-wsdlLocation</extraarg>
                            <extraarg></extraarg>
                            <extraarg>-client</extraarg>
                            <extraarg>-p</extraarg>
                            <extraarg>your.app.pkg2</extraarg>
                        </extraargs>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

并为您拥有的每个 WSDL 文件指定不同的包。根据不同的 WSDL 文件生成的所有类都将在不同的包中生成,您不会遇到任何冲突。

于 2013-01-09T13:34:12.383 回答
0

试试这些教程,解释如何在 Java 应用程序中实现多个 Web 服务:

http://java.dzone.com/articles/tip-multiple-web-service

http://www2.sys-con.com/itsg/virtualcd/webservices/archives/0308/zade/index.html

于 2013-01-08T16:12:48.807 回答