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;
}
WebServices配置:
@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>
答案 0 :(得分:1)
发现问题的原因:我只是忘了放置@EnableWs注释。