1

我正在尝试按照此处编写的方式实现规范化器: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);

但它没有给出任何结果。那么这里可能是什么问题呢?

4

1 回答 1

0

找到了解决方案。bean 必须在 conf/camel.xml 中指定。就我而言,定义如下所示:

<bean name="normalizer" id="normalizer" class="com.myroute.route.normalizer.MyNormalizer"/>
于 2015-04-07T10:33:04.187 回答