SOAP wsdl 返回 404 未找到



Spring Boot project. 调用 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>

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

最新更新