'Marshall error when consuming a soap service using springboot webserver

In view of java 11 no longer supporting webservice soap, I'm trying to consume a soap service using springboot. I'm trying to follow the tutorial on this link "https://spring.io/guides/gs/consuming-web-service/". However, instead of calling a local service, I'm calling a postal service whose wsdl is http://webservice.correios.com.br/service/rastro/Rastro.wsdl. From this wsdl maven is generating the classes: BuscaEventos which would be the request class and BuscaEventosResponse which would be the response class. With the wsdl I passed above, I was able to generate a call through soapUi passing the same call parameters that I use in my code. However, for springboot I get the following error in the last command of class BuscaCliente:

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]

The funny thing is that I can't put the @XmlRootElement annotation in the BuscaEventos class, even because it was generated by maven. And in the tutorial, it is not necessary to do any further steps, or to modify the generated class.

The only thing I had to do other than the tutorial was to set the "schemas" folder, which is the folder where maven created the classes, as a source folder.

Those are my classes:

@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;

}

/////

public class BuscaCliente extends WebServiceGatewaySupport {

public BuscaEventosResponse getBusca() {
    BuscaEventos request = new BuscaEventos();
    request.setUsuario("ECT");
    request.setSenha("SRO");
    request.setTipo("1");
    request.setResultado("T");
    request.setLingua("101");
    request.setObjetos("PY150825065BR");

    System.out.println("Buscando objeto: " + request.getObjetos());


    BuscaEventosResponse response = (BuscaEventosResponse) getWebServiceTemplate()
            .marshalSendAndReceive("http://webservice.correios.com.br/service/rastro/Rastro", request, 
                    new SoapActionCallback(""));
    return response;

}

//// These are the classes generated by mavem from 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;
}

//// This is the 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>


Solution 1:[1]

Indicated in your BuscaEventos.java => @XmlRootElement(name = "buscaEventos")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 procrastinator