2015-04-06 56 views
1

我试图实现正规化它写到这里顺便说一句: http://camel.apache.org/normalizer.html骆驼正规化豆未注册

我得到这个异常:在RouteBuilder

org.apache.camel.NoSuchBeanException: No bean could be found in the registry for 
: normalizer 

我.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); 

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

回答

0

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

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

是的,您需要注册该bean。你可以在你的xml中使用xml配置,或者你可以在你的java配置类中使用它。 –