Camel normalizer bean未注册

时间:2015-04-06 21:22:57

标签: java apache-camel activemq integration-patterns

我试图按照它在这里写的方式实现规范化程序: 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);

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

1 个答案:

答案 0 :(得分:0)

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

<bean name="normalizer" id="normalizer" class="com.myroute.route.normalizer.MyNormalizer"/>