简体   繁体   中英

Jersey Restful exception

I'm facing Jersey 2.7. This is my service:

package edu.srv.rest;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Application;

@Path("/algebra")
public class Algebra extends Application {

    @GET
    @POST
    @Path("/sum")
    public int sum(@QueryParam("a") int a, @QueryParam("b") int b) {
        return a + b;
    }
}

this is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <servlet>
        <servlet-name>RS1</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>edu.srv.rest.Algebra</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>RS1</servlet-name>
        <url-pattern>/algebra/*</url-pattern>
    </servlet-mapping>
</web-app>

and this is my project structure:

项目结构

when I try to deploy (tomcat 6, tomcat 7, tomcat 8) this service as war I got this exception:

java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.model.ContractProvider$Builder

what am I missing?

org.glassfish.jersey.model.ContractProvider$Builder uses javax.inject.Singleton class which is present in javax.inject jar. Include the same to resolve the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM