gpt4 book ai didi

java - SOAP wsdl 返回 404 未找到

转载 作者:行者123 更新时间:2023-12-02 10:51:16 27 4
gpt4 key购买 nike

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;
}

Web 服务配置:

@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注解。

关于java - SOAP wsdl 返回 404 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52165880/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com