春季WS.肥皂请求为null



我有肥皂Web服务。我尝试通过我的要求传递实体。原始类型(包括字符串)通过正常。但是,如果我想发送实体,我的实体是无效的。我有什么错吗?

所有类都是由Maven生成的。

TestUserRequest 
package soap.test.spring_boot_soap_example;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
        "user"
})
@XmlRootElement(name = "testUser")
public class TestUserRequest {
    @XmlElement(required = true)
    private User user;
    public User getUser() {
        return user;
    }
    public void setUser(User name) {
        this.user = name;
    }
}
getters/setters

用户

package soap.test.spring_boot_soap_example;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "user", propOrder = {
    "name",
    "empId",
    "salary"
})
public class User {
    @XmlElement(required = true)
    protected String name;
    @XmlElement(required = true)
    protected int empId;
    @XmlElement(required = true)
    protected double salary;
getters/setters;

端点

    package soap.test.springbootsoapexample.endpoint;
import soap.test.spring_boot_soap_example.TestUserRequest;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
@Endpoint
public class UserEndpoint {
   @PayloadRoot(namespace = "http://soap.test",
            localPart = "testUser")
    public void testUser(@RequestPayload TestUserRequest saveUserRequest) {
       System.out.println(saveUserRequest.getUser());
    }
}

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>soap.test</groupId>
    <artifactId>spring-example</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaDirectory>${project.basedir}/src/main/resources/</schemaDirectory>
                    <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
                    <clearOutputDir>false</clearOutputDir>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

users.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://soap.test"
           targetNamespace="http://soap.test"
           elementFormDefault="qualified">
    <xs:element name="testUserRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="user" type="tns:user" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="user">
        <xs:sequence>
            <xs:element name="name" type="xs:string" />
            <xs:element name="empId" type="xs:int" />
            <xs:element name="salary" type="xs:double" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

和请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:us="http://soap.test">
    <soapenv:Header/>
    <soapenv:Body>
        <us:testUser>
            <us:name>asd</us:name>
            <us:empId>125</us:empId>
            <us:salary>aasdg</us:salary>
        </us:testUser>
    </soapenv:Body>
</soapenv:Envelope>

我在互联网上寻找了这样的问题。但是不幸的是,我什么也没发现

问题在错误的请求中。我没有写用户字段

相关内容

  • 没有找到相关文章

最新更新