![](/img/trans.png)
[英]Configuring Camel Producer with CXF-RS Client Via Spring XML
[英]Configuring Camel With Spring No Xml
我正在嘗試僅使用注釋並直接使用Java使用Spring配置Camel。 這是我創建的一條路線:
@Produce(uri = "activemq:my.route")
ProducerTemplate producer;
@RequestMapping(value = "/test", method = RequestMethod.POST)
public void testCamel()
{
producer.sendBody("TEST");
}
我需要在我的AppConfig類中定義一個駱駝上下文:
我當前的版本:
@Autowired
private ApplicationContext applicationContext;
@Bean
public CamelContext camelContext() throws Exception {
SpringCamelContext springCamelContext = new SpringCamelContext(applicationContext);
springCamelContext.addRoutes(new com.bigideas.routing.Routes());
return springCamelContext;
}
Routes類只是擴展RouteBuilder的空類。
問題是,當我實際調用testCamel方法時,生產者為空。 我知道我可以在xml配置文件中執行上下文,我只是想知道不使用xml時我做錯了什么。
我相信您應該按照此處的說明進行操作: http : CamelConfiguration
,所以一個@Configuration
類使用@ComponentScan
擴展了CamelConfiguration
。
此外,您的com.bigideas.routing.Routes
應該是Spring Bean( @Bean
或@Component
)
使用駱駝2.18和spring-boot,駱駝上下文的建立和單元測試變得非常容易。
看一下這個例子https://github.com/RakeshBhat/rb-camelservlet218-xamples
擴展routebuilder的類應使用@Component注釋。 同樣在Spring Controller類中,您需要自動連接Camel Context,然后使用create producer / consumer模板。 確保您調用模板的開始/停止方法,這樣可以有效利用資源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.