1

I have been trying get the jersey-spring to deploy correctly in wildfly-12.

Below is the error I get

     org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type InjectionManager with qualifiers @Default
  at injection point [UnbackedAnnotatedParameter] Parameter 1 of [UnbackedAnnotatedConstructor] @Inject public org.glassfish.jersey.server.spring.scope.RequestContextFilter(InjectionManager)
  at org.glassfish.jersey.server.spring.scope.RequestContextFilter.<init>(RequestContextFilter.java:101)

        at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:375)
        at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:287)
        at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:140)
        at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:161)
        at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:518)

Below is my pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>jquick2</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>jquick2</name>

    <build>
        <finalName>jquick2</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.ext</groupId>
            <artifactId>jersey-spring4</artifactId>
            <version>2.27</version>
       </dependency>

       <!--  <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            use the following artifactId if you don't need servlet 2.x compatibility
            artifactId>jersey-container-servlet</artifactId
        </dependency> -->
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
        </dependency>
        <!-- uncomment this to get JSON support -->
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-binding</artifactId>
        </dependency>

        <!-- servelet provieded dependency -->
       <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
       </dependency> 

       <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

       <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.ext.cdi/jersey-cdi1x -->
        <dependency>
            <groupId>org.glassfish.jersey.ext.cdi</groupId>
            <artifactId>jersey-cdi1x</artifactId>
            <version>2.15</version>
            <scope>provided</scope>
        </dependency>


    </dependencies>
    <properties>
        <jersey.version>2.27</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
     see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath://sprintconfig.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>


        <!--  <servlet-class>org.glassfish.jersey.spi.spring.container.servlet.SpringServlet</servlet-class> -->
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>test.jquick2</param-value>
        </init-param>

         <!-- <init-param>
             <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
             <param-value>true</param-value>
        </init-param> -->
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>test.config.RestConfig</param-value>
        </init-param>

        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/webapi/*</url-pattern>
    </servlet-mapping>

</web-app>

Restconfig class:

public class RestConfig extends ResourceConfig{

    public RestConfig() {
        register(RequestContextFilter.class);
        register(MyResource.class);
    }

}

I have tried to google, but with no luck, however I did find below stackoverflow question which has little resemblance but old - which at the end looks unresolved.

Spring 2.0.x Jersey 2 Request scoped bean

I have also tried below guide: https://deltaspike.apache.org/documentation/cdiimp.html

In fact, I have added few dependencies in pom I posted for the same reason.

Further, I tried tomcat - code as is without any dependencies added from above links will deploy and run fine in tomcat.

Full project I am trying to run in below link https://github.com/pavankn18/springrestwildfly

Has anyone got this to work in Wildfly? JBoss-Wildfly have good share in web app servers, I was surprised at not finding much content about this problem in internet!.

Any help is appreciated :)

Pavan Kumar
  • 462
  • 5
  • 13
  • Is there a reason to use Jersey over RESTEasy? I'm pretty sure Spring works with both. – James R. Perkins Jun 04 '18 at 15:59
  • I guess it should not matter, now I am using resteasy - still why it should be so difficult to make a app server use the rest implementation of choice? Further I could not get resteasy integration with spring to work correctly. I still get the same problem. Now I am using rest with ejb - atleast this seems to be not that hard in jboss :( – Pavan Kumar Jun 07 '18 at 04:53
  • Still, I would like to know how to resolve it. – Pavan Kumar Jun 07 '18 at 04:54

0 Answers0