views:

1436

answers:

3

Hola guys!

im currently struggling to integrate a REST Service based on Jersey and Spring. I'm using Spring 3.0.2-RELEASE and jersey-spring 1.2.

But jersey-spring adds a dependency to Spring 2.5.6 to my project which of cause conflicts with the 3.0.2-RELEASE to give me thefollwing error:

11:58:25,409 ERROR org.springframework.web.context.ContextLoader:215 - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [cloverjazz-web-context.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.getLocalName(Lorg/w3c/dom/Node;)Ljava/lang/String;
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)

Is there a way to get around this issue? Does anyone know?

Thanks!

+2  A: 

As far as I know they are yet to officially change the jersey-spring maven module to support spring 3.0 instead of 2.5. I also found the following post at nabble forum!

Abdel Olakara
+2  A: 

Own Answer: I simply excluded the dependencies in the pom.xml in the following way. there don't seem to be any incompabilities and everything runs fine so far:

 <dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-spring</artifactId>
    <version>1.2</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </exclusion>
    </exclusions>
</dependency>
smeg4brains
+2  A: 

I don't know if jersey-spring is compatible with Spring 3.0 but the way to control the versions of artifacts used in transitive dependencies is to use dependencyManagement:

<project>
  ...
  <repositories>
    <repository>
      <id>download-java-net</id>
      <url>http://download.java.net/maven/2/&lt;/url&gt;
    </repository>
  </repositories>
  <properties>
    <org.springframework.version>3.0.2.RELEASE</org.springframework.version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>${org.springframework.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.sun.jersey.contribs</groupId>
      <artifactId>jersey-spring</artifactId>
      <version>1.2</version>
      <exclusions>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    ...
  </dependencies>
</project>

Note that it's still required to exclude org.springframework:spring:jar:2.5.6 since this dependency doesn't exist in later versions.

Below, the dependency tree you'll get with this setup:

$ mvn dependency:tree 
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Q2911869
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] com.stackoverflow:Q2911869:jar:1.0-SNAPSHOT
[INFO] +- com.sun.jersey.contribs:jersey-spring:jar:1.2:compile
[INFO] |  +- com.sun.jersey:jersey-server:jar:1.2:compile
[INFO] |  |  +- com.sun.jersey:jersey-core:jar:1.2:compile
[INFO] |  |  |  \- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO] |  |  \- asm:asm:jar:3.1:compile
[INFO] |  +- org.springframework:spring-core:jar:3.0.2.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-asm:jar:3.0.2.RELEASE:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.0.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:3.0.2.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:3.0.2.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:3.0.2.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:3.0.2.RELEASE:compile
[INFO] |     \- aopalliance:aopalliance:jar:1.0:compile
[INFO] \- junit:junit:jar:3.8.1:test
...

Reference

Pascal Thivent