我正在尝试配置 Apache Camel Producer 组件(由camel-archetype-component archetype 生成),并对其中一个部分如何工作有疑问。
端点代码:
@UriEndpoint(firstVersion = "1.0-SNAPSHOT", scheme = "xmlGenerator", title = "xmlGenerator", syntax = "xmlGenerator:testScope",
category = {Category.JAVA, Category.CORE})
public class xmlGeneratorEndpoint extends DefaultEndpoint {
@UriPath
@Metadata(required = true)
private String testScope;
我的问题是,“testScope”从未被使用过。默认设置有 setter/getter,但都没有被调用。
使用
.to("xmlGenerator://hello?option=12")
“testScope”变量永远不会被设置。
即使使用 .to("xmlGenerator://?option=12")
也不会引起问题。我认为应该如此。
如何让它设置该值?
是组件负责设置,需要在组件源码中添加。您需要对所有标有
UriPath
的选项执行此操作。标有 UriParam
的选项可以通过 setProperties...
从组件自动批量映射。
但是看一下现有组件源代码可以更好地理解。
还有一些文档:https://camel.apache.org/manual/writing-components.html
如果您有 CiA2 书,其中有一章/部分是关于编写自定义组件的。