[英]Best way of publish JAX-WS webservices without using main()?
我正在將帶有Camel Cxf組件的Apache Camel用於Web服務。 我有4-5個JAX-WS網絡服務。 我想使用Endpoint.publish發布這些Web服務。 我目前正在做的是在statrtup上發布這些服務,即在WebApplicationContextInitializer中。 誰能指導我在服務器啟動時發布這些服務的最佳和更合適的方法是什么? 注意:我不想在互聯網上看到示例時發布,即
public static void main() {
HelloWorldImpl implementor = new HelloWorldImpl();
String address = "http://localhost:9000/helloWorld";
Endpoint.publish(address, implementor);
}
我不想在發布網絡服務時執行上述操作。
根據您的問題,我假設您沒有使用Spring。 通常,您將CXF Web服務配置為Spring上下文的一部分。 鑒於此,您將要使用CXF Servlet傳輸,然后在擴展CXF類CXFNonSpringServlet的類中發布終結點。 在該類中,您將需要編寫類似於以下內容的代碼來發布端點:
@Override
public void loadBus(ServletConfig servletConfig) throws ServletException {
super.loadBus(servletConfig);
// You could add the endpoint publish codes here
Bus bus = cxf.getBus();
BusFactory.setDefaultBus(bus);
Endpoint.publish("/Greeter", new GreeterImpl());
// You can als use the simple frontend API to do this
ServerFactoryBean factory = new ServerFactoryBean();
factory.setBus(bus);
factory.setServiceClass(GreeterImpl.class);
factory.setAddress("/Greeter");
factory.create();
}
我是從CXF網站上的以下鏈接中檢索到的:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.