You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot暴露SOAP服务问题:访问WSDL时出现404错误

Spring Boot SOAP服务WSDL 404错误排查与解决

核心错误点分析

1. XSD资源加载类型错误

你的accountSchema() Bean中,使用SimpleXsdSchema加载了AccountService.wsdl文件,但SimpleXsdSchema仅用于加载XSD(XML Schema)定义文件,而非WSDL文件。WSDL是基于XSD自动生成的,此处应指向业务逻辑对应的XSD文件。

2. WSDL访问路径不匹配

你定义的DefaultWsdl11Definition Bean的名称为"account",Spring Web Services会以此名称作为WSDL文件的前缀生成访问路径,正确的地址应为 http://localhost:8082/ws/account.wsdl,而非你尝试的AccountService.wsdl。

分步修复方案

步骤1:修正XSD资源配置

假设你的业务XSD文件位于src/main/resources/wsdl/Account.xsd,修改accountSchema()方法:

@Bean
public XsdSchema accountSchema() {
    // 替换为实际的XSD文件路径,而非WSDL文件
    return new SimpleXsdSchema(new ClassPathResource("wsdl/Account.xsd"));
}

步骤2:调整WSDL访问路径

两种可选方案:

  • 方案一:使用正确的访问地址http://localhost:8082/ws/account.wsdl
  • 方案二:修改DefaultWsdl11Definition的Bean名称为"AccountService",适配你原本的访问路径:
@Bean(name = "AccountService") // 修改为目标WSDL文件名前缀
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema accountSchema) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    wsdl11Definition.setPortTypeName("AccountPort");
    wsdl11Definition.setLocationUri("/ws");
    wsdl11Definition.setTargetNamespace("http://example.com/accounts");
    wsdl11Definition.setSchema(accountSchema);
    return wsdl11Definition;
}

步骤3:额外排查验证点

  • 依赖检查:确保项目依赖中包含Spring Web Services核心包与wsdl4j:
    Maven示例:
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
    </dependency>
    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
    </dependency>
    
  • 文件位置验证:确认XSD文件确实存在于src/main/resources/wsdl/目录,打包后能被classpath正确识别。
  • 端口确认:检查Spring Boot应用运行端口是否为8082,可通过控制台日志或application.properties中的server.port配置确认。

内容的提问来源于stack exchange,提问作者Francesco Palopoli

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 13:32:19