【问题标题】:SOAP wsdl returns 404 not foundSOAP wsdl 返回 404 未找到
【发布时间】:2018-09-04 21:15:59
【问题描述】:

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

pom:

<?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>

【问题讨论】:

  • 你为什么要制造战争?您是否将其部署到 servlet 容器?我也怀疑你的Customer 是一个组件。
  • "- 您是否将其部署到 servlet 容器?"是的。 “我也怀疑你的客户是一个组件”你是什么意思?
  • 如果您正在部署应用程序,您的网址不是http://localhost:8080/customer.wsdl,而是`localhost:8080/<app-name>/customer.wsdl. You have annotated your Customer` 类和@Component,但我怀疑它是这样的。
  • 糟糕,是的,@Component 不应该存在。我没有为 url 创建任何前缀,在 localhost 上工作时我不需要它们
  • 运行嵌入式容器时不需要部署它。

标签: java spring-boot soap


【解决方案1】:

问题原因找到了:我只是忘记放@EnableWs注解了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    相关资源
    最近更新 更多