java – 可以用CXF生成可序列化的类吗?

前端之家收集整理的这篇文章主要介绍了java – 可以用CXF生成可序列化的类吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用Apache CXF从WSDL文件生成类,但是它们不实现将对象放入JMS队列所需的Serializable.是否有可能这样做,或者我必须将生成的类转换成我自己的并发送它们?

解决方法

我在这里找到了解决方案,如果有人在将来需要它:

1.将此插件添加到pom.xml

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${basedir}/src/main/java</sourceRoot>
                <wsdlRoot>${basedir}/src/main/resources</wsdlRoot>
                <includes>
                    <include>*Service.wsdl</include>
                </includes>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${basedir}/src/main/resources/your_wsdl.wsdl</wsdl>
                        <extraargs>
                            <extraarg>-client</extraarg>
                            <extraarg>-impl</extraarg>
                            <extraarg>-server</extraarg>
                            <extraarg>-verbose</extraarg>
                            <extraarg>-validate</extraarg>
                        </extraargs>
                        <bindingFiles>
                            <bindingFile>${basedir}/src/main/resources/binding.xml</bindingFile>
                        </bindingFiles>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

2.编写自定义绑定(binding.xml)

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings wsdlLocation="Send.wsdl"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <jaxws:bindings
        node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://wsdl/SendService.wsdl']">
        <jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <jxb:serializable uid="11082011"/>
        </jxb:globalBindings>
    </jaxws:bindings>
</jaxws:bindings>

运行’mvn生成源’

原文链接:https://www.f2er.com/java/123800.html

猜你在找的Java相关文章