【问题标题】:Built in HTTP Server in Apache CXF在 Apache CXF 中内置 HTTP 服务器
【发布时间】:2014-01-21 20:19:55
【问题描述】:

Apache CXF 中是否有内置的 HTTP 服务器,例如 Jersey 的“HttpServerFactory”? 我尝试通读 CXF 文档,但找不到类似的东西。

【问题讨论】:

  • 因为这会复制你可以使用 Jetty 的东西......?

标签: rest jersey cxf httpserver


【解决方案1】:

是的,有。

如果您想在内置服务器上部署 JAX-RS 服务,请使用 org.apache.cxf.jaxrs.JAXRSServerFactoryBean。用法示例(取自CXF samples):

JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(CustomerService.class);
sf.setResourceProvider(CustomerService.class, 
    new SingletonResourceProvider(new CustomerService()));
sf.setAddress("http://localhost:9000/");

sf.create();

如果您想在内置服务器上部署 JAX-WS 服务,您可以使用 javax.xml.ws.Endpoint.publish(..)。示例代码(再次从CXF Sample复制):

    HelloWorldImpl implementor = new HelloWorldImpl();
    String address = "http://localhost:9000/helloWorld";
    Endpoint.publish(address, implementor);

JAX-WS 和 JAX-RS 都需要将 org.apache.cxf:cxf-rt-transports-http-jetty 添加到类路径。

我真的建议看看CXF samples。有时它们是不可或缺的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 2012-05-15
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多