Eric Lefevre-Ardant on Java & Agile

April 23, 2007

How to run XFire 1.x with Spring 2.x and Maven 2.x

Filed under: java, maven, spring, webservices, xfire — Eric Lefevre-Ardant @ 5:13 pm

In version 1.2.5 of XFire, a module called xfire-spring is necessary to run it together with , well, Spring. The issue is that the POM file for it is designed to run with Spring 1.2.x.

This is an excerpt from file xfire-spring-1.2.5.pom:

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>1.2.6</version>
<scope>test</scope>
</dependency>
...
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</dependency>

This last bit is especially deceitful, as it refers to a ’spring’ module… that only exists in Spring 1.x, not in Spring 2.x.

Suppose that you have your own POM where both Spring 2.x and XFire are configured:

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.0.2</version>
</dependency>
...
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-spring</artifactId>
<version>1.2.5</version>
</dependency>

Apparently, because of the configuration of xfire-spring, when running mvn compile, the classpath uses modules from Spring 1.x, although as runtime, modules from Spring 2.x are correctly used.

As long as you are using methods available both in Spring 1.x and Spring 2.x, this won’t really be a problem. This is in fact often the case, which might explain why I never found any reference to this problem on the web

But if you are, like me, using methods only in Spring 2., you’ll get a compilation error.

The fix is to direct Maven to explicitly exclude Spring 1.x:


<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-spring</artifactId>
<version>1.2.5</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>

Update (25/04/07): another thing seems necessary to get this to work.

The example provided with the XFire distribution has a service.xml file that looks like this:

<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>LotDonneesService</name>
...

In practice, it seems to work with Spring 1.x but not with Spring 2.x. The correct syntax is:

<beans>
<service xmlns="http://xfire.codehaus.org/config/1.0">
<name>LotDonneesService</name>
...

This issue is, in fact, described in the official documentation for XFire.

6 Comments »

  1. Thank you very much! saved my day :-)

    Comment by Anonymous — September 25, 2007 @ 4:23 pm

  2. Thanks mate :) I get my xfire 1.2.3 and spring 2.5.0 working.

    Comment by JH — January 19, 2008 @ 1:52 pm

  3. Woohoo… thanks heaps! And that is generated wrongly by MyEclipse too!!!

    Comment by Tony — April 21, 2008 @ 8:22 am

  4. Thanks a lot….

    Comment by Deepak — July 31, 2008 @ 8:53 pm

  5. xfire 1.2.5 and spring 2.5.4 worked fine with this tip. Thanks!

    Comment by Jon Travis — September 25, 2008 @ 7:07 am

  6. Thanks so much, that was really buggin me :)

    Comment by Patrick — February 12, 2010 @ 10:32 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress