Java 使用springboot Web服务器使用soap服务时出现Marshall错误

Java 使用springboot Web服务器使用soap服务时出现Marshall错误,java,spring-boot,soap,Java,Spring Boot,Soap,鉴于Java11不再支持WebServiceSOAP,我尝试使用springboot使用soap服务。我正在尝试按照此链接“”上的教程进行操作。 然而,我没有调用本地服务,而是调用了wsdl为的邮政服务。 从这个wsdl中,maven正在生成类:BuscaEventos(将是请求类)和BuscaEventosResponse(将是响应类)。 通过上面传递的wsdl,我能够通过soapUi生成调用,并传递我在代码中使用的相同调用参数。但是,对于springboot,我在BuscaClient类的最

鉴于Java11不再支持WebServiceSOAP,我尝试使用springboot使用soap服务。我正在尝试按照此链接“”上的教程进行操作。 然而,我没有调用本地服务,而是调用了wsdl为的邮政服务。 从这个wsdl中,maven正在生成类:BuscaEventos(将是请求类)和BuscaEventosResponse(将是响应类)。 通过上面传递的wsdl,我能够通过soapUi生成调用,并传递我在代码中使用的相同调用参数。但是,对于springboot,我在BuscaClient类的最后一个命令中遇到以下错误:

Caused by: org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested 
exception is javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: it is not possible to do marshalling of the type 
"com.example.spring.soap.schemas.BuscaEventos" as an element because it was not found in a annotation @XmlRootElement]
有趣的是,我不能将@XmlRootElement注释放在BuscaEventos类中,即使它是由maven生成的。在本教程中,无需执行任何进一步的步骤,也无需修改生成的类

除了教程之外,我唯一要做的就是将“schemas”文件夹(maven创建类的文件夹)设置为源文件夹

这些是我的课程:

@SpringBootApplication
public class SoapApplication {

    public static void main(String[] args) {
        SpringApplication.run(SoapApplication.class, args);
    }

    @Bean
    CommandLineRunner lookup(BuscaCliente cliente) {
        return args -> {
            BuscaEventosResponse response = cliente.getBusca();
            System.out.println(response.getReturn().toString());
        };
    }
}
////////

@Configuration
public class BuscaConfig {

@Bean
public Jaxb2Marshaller marshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    // this package must match the package in the <generatePackage> specified in
    // pom.xml
    marshaller.setContextPath("com.example.spring.soap.schemas");
    return marshaller;
}

@Bean
public BuscaCliente buscaCliente(Jaxb2Marshaller marshaller) {
    BuscaCliente client = new BuscaCliente();
    client.setDefaultUri("http://webservice.correios.com.br/service/rastro/Rastro");
    client.setMarshaller(marshaller);
    client.setUnmarshaller(marshaller);
    return client;

}
////这些是mavem从wsdl生成的类/////

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "buscaEventosResponse", propOrder = {
"_return"
})
public class BuscaEventosResponse {

@XmlElement(name = "return")
protected Sroxml _return;

/**
 * Obtém o valor da propriedade return.
 * 
 * @return
 *     possible object is
 *     {@link Sroxml }
 *     
 */
public Sroxml getReturn() {
    return _return;
}

/**
 * Define o valor da propriedade return.
 * 
 * @param value
 *     allowed object is
 *     {@link Sroxml }
 *     
 */
public void setReturn(Sroxml value) {
    this._return = value;
}
//////

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "buscaEventos", propOrder = {
"usuario",
"senha",
"tipo",
"resultado",
"lingua",
"objetos"
})
public class BuscaEventos {

protected String usuario;
protected String senha;
protected String tipo;
protected String resultado;
protected String lingua;
protected String objetos;

/**
 * Obtém o valor da propriedade usuario.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getUsuario() {
    return usuario;
}

/**
 * Define o valor da propriedade usuario.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setUsuario(String value) {
    this.usuario = value;
}

/**
 * Obtém o valor da propriedade senha.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getSenha() {
    return senha;
}

/**
 * Define o valor da propriedade senha.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setSenha(String value) {
    this.senha = value;
}

/**
 * Obtém o valor da propriedade tipo.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getTipo() {
    return tipo;
}

/**
 * Define o valor da propriedade tipo.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setTipo(String value) {
    this.tipo = value;
}

/**
 * Obtém o valor da propriedade resultado.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getResultado() {
    return resultado;
}

/**
 * Define o valor da propriedade resultado.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setResultado(String value) {
    this.resultado = value;
}

/**
 * Obtém o valor da propriedade lingua.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getLingua() {
    return lingua;
}

/**
 * Define o valor da propriedade lingua.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setLingua(String value) {
    this.lingua = value;
}

/**
 * Obtém o valor da propriedade objetos.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getObjetos() {
    return objetos;
}

/**
 * Define o valor da propriedade objetos.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setObjetos(String value) {
    this.objetos = value;
}
////这是pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.0.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.sping</groupId>
<artifactId>soap</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>soap</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>11</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <!-- tag::dependency[] -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- end::dependency[] -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<!-- tag::profile[] -->
<profiles>
    <profile>
        <id>java11</id>
        <activation>
            <jdk>[11,)</jdk>
        </activation>

        <dependencies>
            <dependency>
                <groupId>org.glassfish.jaxb</groupId>
                <artifactId>jaxb-runtime</artifactId>
            </dependency>
        </dependencies>
    </profile>
</profiles>
<!-- end::profile[] -->

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <!-- tag::wsdl[] -->
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaLanguage>WSDL</schemaLanguage>
                <generatePackage>com.example.spring.soap.schemas</generatePackage>
                <schemas>
                    <schema>
                        <url>http://webservice.correios.com.br/service/rastro/Rastro.wsdl</url>
                    </schema>
                </schemas>
            </configuration>
        </plugin>
        <!-- end::wsdl[] -->
    </plugins>
</build>
</project>

4.0.0
org.springframework.boot
spring启动程序父级
2.3.0.1发布
com.example.sping
肥皂
0.0.1-快照
肥皂
SpringBoot的演示项目
11
org.springframework.boot
弹簧靴起动器
org.springframework.boot
SpringBootStarterWeb服务
org.springframework.boot
弹簧启动机tomcat
org.springframework.boot
弹簧起动试验
测试
org.junit.vintage
朱尼特老式发动机
爪哇11
[11,)
org.glassfish.jaxb
jaxb运行时
org.springframework.boot
springbootmaven插件
org.jvnet.jaxb2.maven2
maven-jaxb2-plugin
0.13.2
生成
WSDL
com.example.spring.soap.schemas
http://webservice.correios.com.br/service/rastro/Rastro.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.0.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.sping</groupId>
<artifactId>soap</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>soap</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>11</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <!-- tag::dependency[] -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- end::dependency[] -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<!-- tag::profile[] -->
<profiles>
    <profile>
        <id>java11</id>
        <activation>
            <jdk>[11,)</jdk>
        </activation>

        <dependencies>
            <dependency>
                <groupId>org.glassfish.jaxb</groupId>
                <artifactId>jaxb-runtime</artifactId>
            </dependency>
        </dependencies>
    </profile>
</profiles>
<!-- end::profile[] -->

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <!-- tag::wsdl[] -->
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaLanguage>WSDL</schemaLanguage>
                <generatePackage>com.example.spring.soap.schemas</generatePackage>
                <schemas>
                    <schema>
                        <url>http://webservice.correios.com.br/service/rastro/Rastro.wsdl</url>
                    </schema>
                </schemas>
            </configuration>
        </plugin>
        <!-- end::wsdl[] -->
    </plugins>
</build>
</project>