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

Spring Boot+Kotlin调用SOAP服务报错:No marshaller registered

问题:Spring Boot + Kotlin调用SOAP服务时提示无Marshaller注册

项目编译运行正常,但调用/get端点时抛出错误:

java.lang.IllegalStateException: No marshaller registered. Check configuration of WebServiceTemplate.

客户端代码

class ExtraccionCatalogosService: WebServiceGatewaySupport() {
    fun extraer(){
        println("Iniciando extracción de catálogos")
        val request = VehiculoMarca()
        request.proveedor = "XXXXX"
        request.password = "XXXX"
        request.usuario = "AH"
        request.token = "00000000000"
        request.tipoVehiculo = "01"
        request.negocio = ""
        val response = WebServiceTemplate().marshalSendAndReceive("https://pruebas.seguros.com/webservices/cot?wsdl", request, SoapActionCallback("http://ws.units.seguros.com/")) as VehiculoMarcaResponse
        println(response)
    }
}

配置类代码

@Configuration
class ExtraccionMarshaller {
    @Bean
    fun getMarshaller(): Jaxb2Marshaller{
        println("configurando marshaller")
        val jaxb2Marshaller = Jaxb2Marshaller()
        jaxb2Marshaller.contextPath = "com.ws.seguros.models.wsdl"
        return jaxb2Marshaller
    }

    @Bean
    fun getExtraccionCatalogos(jaxb2Marshaller: Jaxb2Marshaller): ExtraccionCatalogosService{
        println("configuracndo extraccion service")
        val extraccionCatalogosService = ExtraccionCatalogosService()
        extraccionCatalogosService.defaultUri = "https://pruebas.seguros.com/webservices/cot?wsdl"
        extraccionCatalogosService.marshaller = jaxb2Marshaller
        extraccionCatalogosService.unmarshaller = jaxb2Marshaller
        return extraccionCatalogosService
    }
}

控制器代码

@RestController
class ExtraccionCatalogosController {
    @Autowired
    lateinit var extraccionCatalogosService: ExtraccionCatalogosService

    @GetMapping("/get")
    fun extraer(){
        val resp = extraccionCatalogosService.extraer()
        println(resp)
    }
}

解决方案

问题核心是客户端代码手动创建了未配置的WebServiceTemplate实例,而非使用WebServiceGatewaySupport已初始化好的模板。

ExtraccionCatalogosService继承自WebServiceGatewaySupport,配置类已经为其注入了marshaller和unmarshaller,这些参数会自动绑定到父类的WebServiceTemplate中。但你在extraer()方法里新建的WebServiceTemplate()是完全空白的实例,没有任何marshaller配置,因此触发错误。

修改客户端代码,直接使用父类提供的已配置模板:

class ExtraccionCatalogosService: WebServiceGatewaySupport() {
    fun extraer(){
        println("Iniciando extracción de catálogos")
        val request = VehiculoMarca()
        request.proveedor = "XXXXX"
        request.password = "XXXX"
        request.usuario = "AH"
        request.token = "00000000000"
        request.tipoVehiculo = "01"
        request.negocio = ""
        // 直接调用父类的marshalSendAndReceive方法,使用已配置好的模板
        val response = marshalSendAndReceive(request, SoapActionCallback("http://ws.units.seguros.com/")) as VehiculoMarcaResponse
        println(response)
    }
}

配置类中已经设置了defaultUri,因此调用时无需重复传入URL参数。修改后,Spring注入的marshaller会被正确应用,解决无marshaller注册的问题。

内容的提问来源于stack exchange,提问作者Adonis Becerra Morales

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 02:15:32