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

Spring Boot整合SOAP WebService启动报错:缺失org.apache.cxf.Bus Bean

解决Spring Boot整合CXF SOAP WebService启动时Bus Bean缺失问题

问题原因

启动报错是因为Spring容器中不存在org.apache.cxf.Bus类型的Bean,通常是缺少CXF与Spring Boot整合的自动配置依赖,或是自动配置未生效导致的。

解决步骤

1. 添加CXF Spring Boot Starter依赖

首先确保项目引入CXF的Spring Boot启动器依赖,它会自动配置Bus等核心Bean:

Maven(pom.xml)

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
    <!-- 选择与Spring Boot版本兼容的CXF版本,比如Spring Boot 2.x对应CXF 3.6.x,Spring Boot 3.x对应CXF 4.x -->
    <version>3.6.2</version>
</dependency>

Gradle(build.gradle)

implementation 'org.apache.cxf:cxf-spring-boot-starter-jaxws:3.6.2'

2. 确认配置类被扫描

检查APIApplication主类是否能扫描到EndpointConfig配置类:

  • 如果两者不在同一包或子包下,需在@SpringBootApplication注解中指定扫描路径:
@SpringBootApplication(scanBasePackages = {"org.endpoint", "org.service"})
public class APIApplication{
    public static void main(String[] args) {
        new SpringApplicationBuilder(APIApplication.class).run(args);
    }
}

3. 手动配置Bus Bean(备选方案)

若自动配置仍未生效,可手动在EndpointConfig中定义Bus Bean:

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
// 其他导入...

@Configuration
public class EndpointConfig {
    // 手动添加Bus Bean
    @Bean
    public Bus bus() {
        return new SpringBus();
    }

    @Bean
    public EndpointImpl getInfo(Bus bus, MyService service) {
        EndpointImpl endpoint = new EndpointImpl(bus, service);
        endpoint.publish("/info");
        return endpoint;
    }
}

验证

重新启动应用,Spring容器会自动创建Bus Bean,getInfo方法可正常注入依赖,启动报错即可解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 09:10:56