18

Is it possible to use CXF with Tomcat and without Spring? If so, how?

KobeJohn
  • 7,390
  • 6
  • 41
  • 62
Maurice Perry
  • 32,610
  • 9
  • 70
  • 97

4 Answers4

26

You can configure CXF programmatically without Spring. See the code examples here. Putting the web application context path together with the end point extension--Greeter in the code example--will display a summary page in the browser with a link to the WSDL.

No Spring necessary, giving CXF a very small footprint. I found the only jars necessary to be (for CXF 2.2.1):

  • XmlSchema-1.4.5.jar
  • cxf-2.2.3.jar
  • wsdl4j-1.6.2.jar

I believe neethi-2.0.4.jar may also be necessary for some configurations, but I haven't needed it.

Have fun!

12

I suppose you mean to create a Web Service with CFX that it would run in Tomcat? This is totally possible and Spring is optional. You don't have to use it, if you don't want to.

kgiannakakis
  • 103,016
  • 27
  • 158
  • 194
1

CXF is meant to be used with spring. It is strange you want to use it without it.

You could try NoSpringServletServer and use the ServerFactoryBean or JaxWS API.

Here is the code for the NoSpringServletServer.

But you will still need spring as a dependency. The basic JaxWS can be done without spring. But for almost anything else you will need at the very least spring-core.jar

Paul
  • 19,704
  • 14
  • 78
  • 96
HMM
  • 2,987
  • 1
  • 20
  • 30
  • Well actually, I was thinking about building a webapp that would be deployed as a war file in tomcat, not a standalone server. So I don't need Jetty neither. – Maurice Perry Mar 27 '09 at 18:15
  • A webapp deploys on tomcat just as in any other servlet container (almost). The example shows a standalone server, but the servlet can be referenced from a web.xml. CXFNonSpringServlet extends Servlet you know. – HMM Mar 27 '09 at 18:38
  • That link appears to be no longer valid. Here's an alternate source of information: http://cxf.apache.org/docs/servlet-transport.html#ServletTransport-UsingtheservlettransportwithoutSpring – Jim Rush Aug 02 '10 at 16:31
  • 3
    Why is it strange you'd want to use CXF without Spring? Assuming you don't already use Spring in your app, it's a HUGE pile of dependencies just to get a webservice working. It's definitely possible to run CXF without even Spring Core. You write more code, but less XML, so it's a trade-off. – pendor Jun 26 '13 at 14:09
-1

I dont think it is possible to use CXF completely independent of spring in Tomcat.

Reason is that when I do a Maven dependency tree list (mvn dependency:tree) for a bare minimum CXF webservice, the following is listed (which shows that it needs Spring)

     +- org.apache.cxf:cxf-rt-core:jar:2.2.2:compile
[INFO] |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.1.9:compile

[INFO] |  |  +- org.springframework:spring-core:jar:2.5.5:compile

[INFO] |  |  +- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.6:compile

    org.apache.cxf:cxf-rt-transports-http:jar:2.2.2:compile
[INFO]    \- org.springframework:spring-web:jar:2.5.5:compile

[INFO]       +- commons-logging:commons-logging:jar:1.1.1:compile
skaffman
  • 398,947
  • 96
  • 818
  • 769
  • 2
    just use org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet – Dudi May 09 '14 at 14:31
  • 1
    I agree the dependency tree will still have transitive spring dependencies, agreed with @bercolax , programmatically the spring api XML config can be avoided – Ashoka Dec 20 '15 at 10:33