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

Spring Boot中JAXWS SOAP端点同端口部署及OpenShift端口监听配置问题

Spring Boot中JAXWS SOAP端点同端口部署及OpenShift端口监听配置问题

嗨,我之前也碰到过类似的JAX-WS和Spring Boot整合的问题,给你两个针对性的解决方案,应该能解决你的困扰:


方案一:让SOAP端点和Spring Boot共用同一个端口(推荐)

你当前用Endpoint.publish()的方式会启动JDK自带的独立HTTP服务器,所以会和Spring Boot的内置Tomcat端口冲突,报“port in use”错误。要解决这个问题,我们需要把SOAP端点整合到Spring Boot的内置容器里,共用同一个端口。

步骤1:添加Apache CXF依赖

在你的pom.xml中加入适配Spring Boot 2.7.x和Jakarta API 4.0.1的CXF Spring Boot Starter:

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
    <version>3.6.2</version>
</dependency>

步骤2:修改配置类,用CXF发布端点

替换原来的Endpoint Bean,改用CXF的EndpointImpl绑定到Spring容器:

package net.gencat.salut.sivec.external.cases.config;

import jakarta.xml.ws.Endpoint;
import lombok.extern.slf4j.Slf4j;
import net.gencat.salut.sivec.external.cases.argo.CarregaImpl;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.ApplicationContext;

@Configuration
@Slf4j
public class WebServiceConfig {

    @Bean
    public CarregaImpl carregaImpl() {        
        return new CarregaImpl();
    }

    @Bean
    public Endpoint publishEndpoint(ApplicationContext context, CarregaImpl carregaImpl) {
        // 用Spring容器上下文初始化CXF端点
        EndpointImpl endpoint = new EndpointImpl(context, carregaImpl);
        // 发布路径(相对于Spring Boot根路径)
        endpoint.publish("/ws");
        // 完整地址为Spring Boot端口 + /ws,比如http://localhost:8080/ws
        log.info("SOAP端点已发布: http://localhost:${server.port}/ws");
        return endpoint;
    }
}

验证

启动Spring Boot后,访问http://localhost:你的SpringBoot端口/ws?wsdl就能看到SOAP的WSDL文档,不会再出现端口冲突问题。


方案二:使用独立端口并适配OpenShift部署

如果一定要用独立端口(比如8989),需要解决OpenShift中localhost绑定导致的访问问题:

步骤1:修改端点绑定地址

把soapProperties.getUri()的值从http://localhost:8989/ws/改成http://0.0.0.0:8989/ws/。0.0.0.0表示监听所有网卡,这样在OpenShift容器中外部就能访问到这个端口了。

步骤2:OpenShift配置调整

  • 在Deployment/DeploymentConfig中,添加容器端口暴露配置,标记8989为暴露端口。
  • 创建对应的Service,把容器的8989端口映射到集群内部端口(或NodePort/LoadBalancer,根据访问需求)。
  • 确保OpenShift网络策略允许外部访问该端口。

验证

部署到OpenShift后,通过Service地址访问http://你的Service地址:8989/ws?wsdl,就能正常访问SOAP端点了。


额外注意事项

  • 如果你用Java 11+,若有module-info.java,需开放jakarta.xml.ws相关模块权限。
  • 用SoapUI或Postman测试SOAP请求时,记得使用正确的端点地址和SOAPAction头。

备注:内容来源于stack exchange,提问作者Reyfren

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.17 11:49:35