CXF and Google Guice using JAX-RS + JAX-WS

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 04:09:56

With CXF 2.4.x, CXF no longer uses Spring to internally configure itself. Thus, you can do pretty much anything without Spring.

The configuration parts are definitely an issue. However, all the spring configuration stuff is just thin wrappers over the CXF API's. Thus, you can configure pretty much everything via the API's. You may just need to dig a little bit more.

As an example, with CXF 2.4, we now have started to support using Blueprint instead of Spring in OSGi. The blueprint support doesn't require any of the Spring stuff, but is modelled from it.

Here is what I have been using (cxf-2.5.0).

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

    @Inject
    public WebServiceServlet(SamaService samaService) {
        this.samaService = samaService;
    }

    @Override
    protected void loadBus(ServletConfig sc) {
        super.loadBus(sc);
        BusFactory.setDefaultBus(getBus());
        Endpoint.publish("/Data.asmx", samaService);
    }
}

You've got a problem. CXF is thoroughly dependent on Spring, due to it being internally configured by Spring and using Spring's facilities quite extensively. As such, I don't think it's practical to try to prise CXF out of Spring just so you can use Guice instead; at a minimum, you'd have to replicate all the configuration with custom Guice providers and it still will not work (parts of CXF use some of Spring's Web layer).

You could try using Spring's JavaConfig style for your code instead. That's mostly similar to the sorts of things that Guice does (as far as I can see). Or I suppose you could try using two separate DI frameworks in the same app… though that feels to me like an opportunity for “hilarious” failure.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!