骆驼规范器 bean 未注册
Camel normalizer bean not registered
我正在尝试按照此处编写的方式实现规范化器:
http://camel.apache.org/normalizer.html
我遇到了这个异常:
org.apache.camel.NoSuchBeanException: No bean could be found in the registry for
: normalizer
我在 RouteBuilder 中的 .configure() 看起来像这样:
public void configure() throws Exception {
JndiContext context = new JndiContext();
context.bind("normalizer", new MyNormalizer());
CamelContext camelContext = new DefaultCamelContext(context);
camelContext.addRoutes(this);
from("activemq:queue:input.splitter")
.split().tokenizeXML("person").streaming()
.to("activemq:queue:output.splitter");
from("activemq:queue:input.normalizer")
.choice()
.when().xpath("//persons/person/position").to("bean:normalizer?method=positionChange")
.end()
.to("activemq:queue:output.normalizer");
}
标准化器如下所示:
public class MyNormalizer {
public void positionChange(Exchange exchange, @XPath("//persons/person/position") String name) {
exchange.getOut().setBody(createPerson(name));
}
private String createPerson(String name) {
return name;
}
}
我找到了一种将那段代码添加到 RouteBuilder 中的解决方案:
JndiContext context = new JndiContext();
context.bind("normalizer", new MyNormalizer());
CamelContext camelContext = new DefaultCamelContext(context);
但是没有给出任何结果。
那么这里可能是什么问题?
已找到解决方案。
必须在 conf/camel.xml 中指定 bean。
在我的例子中,定义如下所示:
<bean name="normalizer" id="normalizer" class="com.myroute.route.normalizer.MyNormalizer"/>
我正在尝试按照此处编写的方式实现规范化器: http://camel.apache.org/normalizer.html
我遇到了这个异常:
org.apache.camel.NoSuchBeanException: No bean could be found in the registry for
: normalizer
我在 RouteBuilder 中的 .configure() 看起来像这样:
public void configure() throws Exception {
JndiContext context = new JndiContext();
context.bind("normalizer", new MyNormalizer());
CamelContext camelContext = new DefaultCamelContext(context);
camelContext.addRoutes(this);
from("activemq:queue:input.splitter")
.split().tokenizeXML("person").streaming()
.to("activemq:queue:output.splitter");
from("activemq:queue:input.normalizer")
.choice()
.when().xpath("//persons/person/position").to("bean:normalizer?method=positionChange")
.end()
.to("activemq:queue:output.normalizer");
}
标准化器如下所示:
public class MyNormalizer {
public void positionChange(Exchange exchange, @XPath("//persons/person/position") String name) {
exchange.getOut().setBody(createPerson(name));
}
private String createPerson(String name) {
return name;
}
}
我找到了一种将那段代码添加到 RouteBuilder 中的解决方案:
JndiContext context = new JndiContext();
context.bind("normalizer", new MyNormalizer());
CamelContext camelContext = new DefaultCamelContext(context);
但是没有给出任何结果。 那么这里可能是什么问题?
已找到解决方案。 必须在 conf/camel.xml 中指定 bean。 在我的例子中,定义如下所示:
<bean name="normalizer" id="normalizer" class="com.myroute.route.normalizer.MyNormalizer"/>