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

Apache Camel自定义Producer组件testScope参数无法自动赋值的问题咨询

问题解决步骤

1. 修正@UriEndpoint的syntax定义

你的@UriEndpoint注解里的syntax参数格式错误,必须用{}包裹路径参数名,Camel才能识别这是需要绑定的UriPath参数,进而自动赋值到testScope字段。修改后的代码如下:

@UriEndpoint(firstVersion = "1.0-SNAPSHOT", scheme = "xmlGenerator", title = "xmlGenerator", syntax = "xmlGenerator:{testScope}",
        category = {Category.JAVA, Category.CORE})
public class XmlGeneratorEndpoint extends DefaultEndpoint { // 建议遵循Java驼峰命名规范,类名首字母大写

    @UriPath
    @Metadata(required = true)
    private String testScope;

    // 保留自动生成的getter/setter方法
}

2. 验证URI格式

现在使用标准URI格式:xmlGenerator:hello?option=12(注意不需要额外的//,Camel组件URI的标准格式是scheme:path),此时testScope会被自动赋值为hello。如果不传路径参数(比如xmlGenerator:?option=12),Camel会因为testScope被标记为必填而抛出异常,符合预期的校验逻辑。

3. 额外提示:Java命名规范

虽然不影响功能,但类名建议改为XmlGeneratorEndpoint(首字母大写),遵循Java驼峰命名约定,避免代码风格问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 09:33:22