Publishing JAX-WS Webservice with Guice in a Servlet Application

大城市里の小女人 提交于 2019-12-02 01:46:19

We finally solved it quite elegantly by extending CXFNonSpringServlet. You simply override the loadBus() method where you can configure all your service endpoints.

@Singleton
public class SoapServlet extends CXFNonSpringServlet {
    private static final long serialVersionUID = 1L;

    private final SomeFacade someFacade;

    @Inject
    SoapMachineServlet(final SomeFacade someFacade) {
        this.someFacade = someFacade;
    }

    @Override
    public void loadBus(ServletConfig servletConfig) throws ServletException {
        super.loadBus(servletConfig);

        Bus bus = getBus();
        BusFactory.setDefaultBus(bus);
        Endpoint.publish("/SomeFacade", someFacade);
    }
}

The class itself is a simply a servlet, which can then be bound using a ServletModule:

public class SomeModule extends ServletModule {
    @Override
    protected void configureServlets() {
        serve("/some/path*").with(SoapServlet.class);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!