我面对泽西岛2.7。这是我的服务:
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;
}
}
这是我的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>
这是我的项目结构:
当我尝试部署(tomcat 6,tomcat 7,tomcat 8)这项服务作为战争我得到了这个例外:
java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.model.ContractProvider$Builder
我错过了什么?
答案 0 :(得分:2)
org.glassfish.jersey.model.ContractProvider$Builder
使用javax.inject.Singleton
jar中的javax.inject
类。包括相同内容以解决问题。