Sping4 Jersey2 integration: Adding jersey-spring4 my web the project causes deployment failure and exception

2003 views java
7

I am tring to integrate spring 4 with jersey 2.

However this exception is thrown and deployment on glassfish 4.1.1 fails:

java.lang.AbstractMethodError: org.glassfish.jersey.server.spring.SpringComponentProvider.initialize(Lorg/glassfish/hk2/api/ServiceLocator;)V

If I remove the jersey-spring4.jar the the deployment seceeds but of course then there is no integration.

my

pom.xml

<properties>
       <struts2.version>2.5.18</struts2.version> 
       <log4j2.version>2.10.0</log4j2.version>
       <spring.version>4.3.13.RELEASE</spring.version>
</properties>
.....
.....
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
     <version>${spring.version}</version> 
</dependency>
 <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
 <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${spring.version}</version>
</dependency>

    <!-- REST API --> 
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.3.2</version>
        <scope>provided</scope>
    </dependency>
        <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.bundles/jaxrs-ri -->      
        <dependency>
            <groupId>org.glassfish.jersey.bundles</groupId>
            <artifactId>jaxrs-ri</artifactId>
            <version>2.27</version>    
            <scope>provided</scope>
            <type>zip</type>
        </dependency>
           <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
        <dependency>
           <groupId>javax.xml.bind</groupId>
           <artifactId>jaxb-api</artifactId>
           <version>2.2.7</version>
           </dependency>
        <!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
           <dependency>
           <groupId>javax.ws.rs</groupId>
           <artifactId>javax.ws.rs-api</artifactId>
           <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.ext</groupId>
            <artifactId>jersey-spring4</artifactId>
            <version>2.27</version>
        </dependency>
        <dependency>
           <groupId>org.slf4j</groupId>
           <artifactId>slf4j-api</artifactId>
           <version>1.7.12</version>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
          <version>1.7.12</version>
        </dependency>

Full stack trace:

java.lang.AbstractMethodError: org.glassfish.jersey.server.spring.SpringComponentProvider.initialize(Lorg/glassfish/hk2/api/ServiceLocator;)V
    at org.glassfish.jersey.server.ApplicationHandler$4.get(ApplicationHandler.java:406)
    at org.glassfish.jersey.server.ApplicationHandler$4.get(ApplicationHandler.java:397)
    at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:340)
    at org.glassfish.jersey.server.ApplicationHandler.createApplication(ApplicationHandler.java:364)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:340)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:390)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:362)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5732)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5977)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
    at com.sun.enterprise.web.

answered question

Can you provide the whole stack trace?

@CristianoBombazar done

1 Answer

1

For your jersey version with Spring you should still use working jersey-spring3 version 2.19

posted this

Have an answer?

JD

Please login first before posting an answer.