首页 > 解决方案 > SOAP wsdl 返回 404 未找到

问题描述

Spring Boot 项目。调用http://localhost:8080/customer.wsdl时,我应该得到 WSDL 文档,但是却得到 404 错误页面。有什么想法可能是错的吗?XSD 是通过 IntellijIdea 生成的,我只是在那里手动添加了 targetNamespace。

起居室:

<?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>com.myproj.webservices</groupId>
    <artifactId>simulator</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>simulator</name>
    <description>WebServices Simulator project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.15.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.7</java.version>            
    </properties>

    <build>
        <finalName>${artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
         </plugins>
    </build>

    <dependencies>
        <!--SPRING-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--XML-->
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
        </dependency>

        <!--OTHER-->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.2</version>
        </dependency>
    </dependencies>

</project>

域java类:

@Component
@Entity
@Table(name = "CUSTOMER")
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(exclude = "id")
public class Customer {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(unique = true, nullable = false, name = "customer_id")
    private String customerId;

    @Column(nullable = false, name = "date")
    private Timestamp date;

    @Column(nullable = false, name = "country")
    private String country;

    @Column(name = "market_segment")
    private String marketSegment;

    @Column(name = "company_name")
    private String companyName;

    @Column(nullable = false, name = "currency")
    private String currency;
}

网络服务配置:

@Configuration
public class WebServicesConfig {

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext context) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(context);
        servlet.setTransformWsdlLocations(true);

        return new ServletRegistrationBean(servlet, "/");
    }

    @Bean(name = "customer")
    public DefaultWsdl11Definition customerIdWsdl11Definition() {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("customer");
        wsdl11Definition.setLocationUri("/");
        wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
        wsdl11Definition.setSchema(customerSchema());

        return wsdl11Definition;
    }

    @Bean
    public XsdSchema customerSchema() {
        return new SimpleXsdSchema(new ClassPathResource("customer.xsd"));
    }
}

xsd:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://spring.io/guides/gs-producing-web-service"
           elementFormDefault="qualified">


    <xs:complexType name="customer">
        <xs:sequence>
            <xs:element name="companyName" type="xs:string" minOccurs="0"/>
            <xs:element name="country" type="xs:string" minOccurs="0"/>
            <xs:element name="currency" type="xs:string" minOccurs="0"/>
            <xs:element name="customerId" type="xs:string" minOccurs="0"/>
            <xs:element name="date" type="timestamp" minOccurs="0"/>
            <xs:element name="id" type="xs:long"/>
            <xs:element name="marketSegment" type="xs:string" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="timestamp">
        <xs:sequence>
            <xs:element name="nanos" type="xs:int"/>
        </xs:sequence>
    </xs:complexType>

</xs:schema>

标签: javaspring-bootsoap

解决方案


问题原因找到了:刚才忘记放@EnableWs注解了。


推荐阅读