【问题标题】:Best way of publish JAX-WS webservices without using main()?不使用 main() 发布 JAX-WS Web 服务的最佳方式?
【发布时间】:2014-11-14 17:59:49
【问题描述】:

我正在将 Apache Camel 与 Camel Cxf 组件一起用于 Web 服务。我有 4-5 个 JAX-WS Web 服务。我想使用 Endpoint.publish 发布这些 Web 服务。我目前正在做的是在 statrtup 上发布这些服务,即在 WebApplicationContextInitializer 中。谁能指导我在服务器启动时发布这些服务的最佳和更合适的方式是什么? 注意:我不想发布,因为我在 Internet 上看到了示例,即

public static void main() {
   HelloWorldImpl implementor = new HelloWorldImpl();
   String address = "http://localhost:9000/helloWorld";
   Endpoint.publish(address, implementor);
}

我不想在上面做这件事来发布网络服务。

【问题讨论】:

  • 你在什么服务器上运行?您要将其发布到 ServiceMix 吗? JBossFuse?卡拉夫?

标签: java web-services jax-ws apache-camel


【解决方案1】:

根据您的问题,我假设您没有使用 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 网站上的以下链接中检索到的:

http://cxf.apache.org/docs/servlet-transport.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 2023-04-10
    • 2010-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多