[英]Setup Apache Camel Rest route using Java DSL on Wildfly Swarm
我正在嘗試在Wildfly Swarm中設置Camel Rest服務,但我不確定RouteBuilder
類如何實例化,甚至CamelContext
也如何實例化。 我已經下載了Wildfly Swarm示例,並查看了Camel CXF-JAXRS項目,這很有意義,但是它使用XML定義了路線。 我想使用Java DSL。 我的RouteBuilder
類如下所示:
public class GreetingService extends RouteBuilder {
@Override
public void configure() {
System.out.println("RouteBuilder.configure");
restConfiguration().host("localhost").port("9797");
rest("/say")
.get("/hello").to("direct:hello")
.get("/bye").consumes("application/json").to("direct:bye")
.post("/bye").to("mock:update");
from("direct:hello")
.transform().constant("Hello World");
from("direct:bye")
.transform().constant("Bye World");
}
}
我已經嘗試過使用camel-context.xml
文件,也可以不使用。 Swarm啟動,但是我無法瀏覽到其余服務端點。
如何調用RouteBuilder
? 我應該有某種實例化CamelContext
的main
方法嗎?
我正在使用Widlfy Swarm 2017.8.1,並且該類在war
文件中。
您可以在web.xml中添加此偵聽器以引導駱駝。
org.apache.camel.component.servletlistener.SimpleCamelServletContextListener
或者您可以使用spring來定義駱駝上下文
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.