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

Java 21升级Apache Camel时CXF XSD资源缺失问题求助

解决Java 21 + Camel下cxf:cxfEndpoint的Java DSL替代方案

首先明确:<cxf:cxfEndpoint>标签对应的Java类是org.apache.camel.component.cxf.CxfEndpoint,你可以通过以下步骤完成XML到Java DSL的迁移,同时解决Jakarta适配问题:

1. 引入适配Jakarta的Camel CXF依赖

移除旧的org.apache.camel:cxf:camel-cxf,替换为Jakarta版本的依赖(需确保Camel版本为4.x及以上,这是Camel全面支持Jakarta EE的版本线):

<!-- Maven依赖示例 -->
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-cxf-jakarta</artifactId>
    <version>${camel.version}</version>
</dependency>

这个依赖自带http://camel.apache.org/schema/cxf/camel-cxf.xsd资源,能解决你遇到的XSD找不到的报错。

2. 用Java DSL替代cxf:cxfEndpoint配置

假设你原来的XML配置是这样的:

<cxf:cxfEndpoint id="internalSoapEndpoint" 
                 address="/internal/soap/api" 
                 serviceClass="com.yourcompany.service.InternalSoapService"
                 dataFormat="PAYLOAD"
                 wsdlLocation="classpath:wsdl/internal-service.wsdl"/>

对应的Java配置(Spring环境下用@Configuration类):

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.CxfEndpoint;
import org.apache.camel.component.cxf.DataFormat;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CamelSoapConfig {

    // 定义CxfEndpoint Bean,对应XML里的<cxf:cxfEndpoint>
    @Bean("internalSoapEndpoint")
    public CxfEndpoint internalSoapEndpoint() {
        CxfEndpoint endpoint = new CxfEndpoint();
        // 设置对应XML属性
        endpoint.setAddress("/internal/soap/api");
        endpoint.setServiceClass(InternalSoapService.class);
        endpoint.setDataFormat(DataFormat.PAYLOAD);
        endpoint.setWsdlLocation("classpath:wsdl/internal-service.wsdl");
        
        // 如果原来XML有其他属性,比如bindingId、features等,直接调用setter
        // 示例:设置SOAP绑定
        // endpoint.setBindingId("http://schemas.xmlsoap.org/wsdl/soap/http");
        // 示例:添加日志Feature
        // List<Feature> features = new ArrayList<>();
        // features.add(new LoggingFeature());
        // endpoint.setFeatures(features);
        
        return endpoint;
    }

    // 定义Camel路由,引用上面的Endpoint
    @Bean
    public RouteBuilder soapApiRoute() {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("cxf:bean:internalSoapEndpoint")
                    .log("Received internal SOAP request: ${body}")
                    .to("bean:internalSoapRequestProcessor"); // 替换为你的业务处理逻辑
            }
        };
    }
}

3. 关键注意点

  • 所有原来XML中<cxf:cxfEndpoint>的属性,都能通过CxfEndpoint类的setter方法对应设置,可查看该类的源码确认属性映射。
  • 确保项目中所有javax相关的依赖都替换为jakarta版本,比如Spring框架也要用6.x及以上(适配Java 17+)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 09:01:07