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

SpringBoot SOAP服务配置方法未调用问题排查求助

问题排查与修复

核心问题分析

你的配置类中存在依赖注入不匹配和拼写错误,导致Spring无法正确初始化这些Bean方法:

1. 依赖注入参数不匹配

calculatorServiceDefinition方法声明的参数是XsdSchema calculatorServiceSchema,但你实际定义的XSD Schema Bean是fileUplaodServiceSchema,Spring找不到对应名称的Bean,导致该方法无法被调用。同时你在方法内直接调用fileUplaodServiceSchema(),这会创建一个脱离Spring容器管理的实例,而非使用容器中的Bean。

2. 多处拼写不一致

代码里fileuplaod(少了一个d)的拼写错误出现在:

  • locationUri("/ws/fileuplaod-service")
  • targetNamespace("http://infokristaly.hu/fileuplaod")
    另外方法名calculatorServiceDefinition和实际的文件上传服务功能不符,容易造成混淆。

修复后的代码

package hu.infokristaly.fileservice;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;

@Configuration
@EnableWs
public class SOAPWebServiceConfig extends WsConfigurerAdapter {
    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }

    @Bean(name = "FileUploadServiceWsdl")
    public DefaultWsdl11Definition fileUploadServiceDefinition(XsdSchema fileUplaodServiceSchema) {
        DefaultWsdl11Definition wsdlDefinition = new DefaultWsdl11Definition();
        wsdlDefinition.setPortTypeName("FileUploadServicePort");
        wsdlDefinition.setLocationUri("/ws/fileupload-service");
        wsdlDefinition.setTargetNamespace("http://infokristaly.hu/fileupload");
        wsdlDefinition.setSchema(fileUplaodServiceSchema); // 使用注入的Spring Bean
        return wsdlDefinition;
    }

    @Bean
    public XsdSchema fileUplaodServiceSchema() {
        return new SimpleXsdSchema(new ClassPathResource("fileupload.xsd"));
    }
}

额外验证步骤

  1. 确认启动类的@SpringBootApplication注解覆盖了hu.infokristaly.fileservice包,若未覆盖,添加@ComponentScan(basePackages = "hu.infokristaly.fileservice")到启动类。
  2. 在每个@Bean方法中添加断点或日志,启动应用后检查是否进入方法。
  3. 使用Spring Boot Actuator的/beans端点(需添加actuator依赖),查看messageDispatcherServlet、fileUplaodServiceSchema、fileUploadServiceDefinition是否在Bean列表中。

内容的提问来源于stack exchange,提问作者Papp Zoltán

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 07:32:09