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

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.

About Eric Lefevre-Ardant

Independent technical consultant.
This entry was posted in java, maven, spring, webservices, xfire. Bookmark the permalink.

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

  1. Anonymous says:

    Thank you very much! saved my day :-)

  2. JH says:

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

  3. Tony says:

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

  4. Deepak says:

    Thanks a lot….

  5. Jon Travis says:

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

  6. Patrick says:

    Thanks so much, that was really buggin me :)

Comments are closed.