Java SOAP wsdl返回404未找到

Java SOAP wsdl返回404未找到,java,spring-boot,soap,Java,Spring Boot,Soap,SpringBoot项目。 调用时,我应该得到WSDL文档,但我得到的是404错误页面。你知道哪里不对吗? XSD是通过IntellijIdea生成的,我只是在那里手动添加了targetNamespace pom: Web服务配置: @Configuration public class WebServicesConfig { @Bean public ServletRegistrationBean messageDispatcherServlet(ApplicationCon

SpringBoot项目。 调用时,我应该得到WSDL文档,但我得到的是404错误页面。你知道哪里不对吗? XSD是通过IntellijIdea生成的,我只是在那里手动添加了targetNamespace

pom:

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:



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

您正在创建一场战争,为什么?您是否将其部署到servlet容器中?我还怀疑您的
客户
是否是一个组件。“-您是否将其部署到servlet容器中?”是的。“我也怀疑你的客户是一个组件”你是什么意思?如果你正在部署应用程序,你的url不是
http://localhost:8080/customer.wsdl
而是`
。您已经用
@Component
注释了您的
Customer`class,但我怀疑它是不是这样的。哎呀,是的,@Component不应该在那里。我没有为url创建任何前缀,我在使用LocalHost时不需要它们,而在运行嵌入式容器时则不需要。
@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"));
    }
}
<?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>