Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring Boot中将soap响应转换回xml字符串_Java_Xml_Spring_Jaxb - Fatal编程技术网

Java 在Spring Boot中将soap响应转换回xml字符串

Java 在Spring Boot中将soap响应转换回xml字符串,java,xml,spring,jaxb,Java,Xml,Spring,Jaxb,我用的是弹簧靴。 我已经使用ApacheCXF生成了soap请求/响应对象 <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>3.3.3</version> <executions> <execution&g

我用的是弹簧靴。 我已经使用ApacheCXF生成了soap请求/响应对象

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>3.3.3</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${project.build.directory}/generated-sources</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${basedir}/src/main/resources/wsdl/...</wsdl>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>
但我得到以下错误消息:

“无法将类型\”com.uk.services.consumer.schema.v4.search.searchresponse.QuotationSearchResponse \“封送为元素,因为它缺少@XmlRootElement注释”}

如何将apacheCXF创建的对象序列化回XML。 我正在使用弹簧靴


作为参考,从CXF生成的源代码如下所示

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "QuotationSearchResponse")
public class QuotationSearchResponse
    extends CommonResponse
{   
}

如果要封送没有@XmlRootElement注释的对象,可以尝试更改此行:

marshaller.marshal(instance, sw);
进入此(相应地更改InstanceClass)

marshaller.marshall(新的JAXBElement(新的QName(“uri”,“local”),InstanceClass.class,instance),sw);

看看Hi@Villat,非常感谢,您是否介意分享如何从uri/local XML中重新水化java类,重新加载XML有什么注意事项吗?
marshaller.marshal(instance, sw);
marshaller.marshal(new JAXBElement<InstanceClass>(new QName("uri","local"), InstanceClass.class, instance), sw);