2015-04-06 55 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配置類中使用它。 –