Web services JAX-RS2.0RESTfulWebService和Tomcat8.0的部署错误

Web services JAX-RS2.0RESTfulWebService和Tomcat8.0的部署错误,web-services,rest,maven,tomcat,jax-rs,Web Services,Rest,Maven,Tomcat,Jax Rs,我是编写REST Web服务的新手。 目前,我正在尝试使用jersey-2.x和Tomcat8.0编写一个RESTful服务 但是,当我尝试在eclipse中部署时,会出现如下错误: java.lang.NoSuchMethodError:javax.ws.rs.core.Application.getProperties()Ljava/util/Map 我所做的是: 我写了以下课程: @ApplicationPath("resources") public class RestTestAppl

我是编写REST Web服务的新手。 目前,我正在尝试使用jersey-2.x和Tomcat8.0编写一个RESTful服务 但是,当我尝试在eclipse中部署时,会出现如下错误:

java.lang.NoSuchMethodError:javax.ws.rs.core.Application.getProperties()Ljava/util/Map

我所做的是:

  • 我写了以下课程:

    @ApplicationPath("resources")
    public class RestTestApplication extends Application
    {
        @Override
        public Set<Class<?>> getClasses() {
            final Set<Class<?>> classes = new HashSet<Class<?>>();
            // register root resource
            classes.add(HelloResource.class);
            return classes;
        }
    }
    
    @Path("sayhello")
    public class HelloResource
    {
        @GET
        @Produces("text/plain")
        public String sayhello ()
        {
            return "Hi, How are you !!";
        }
    }
    
    @ApplicationPath(“资源”)
    公共类RestTestApplication扩展了应用程序
    {
    @凌驾
    public Set>classes=new hashset在服务器上运行

  • 获取上面提到的错误


  • 请让我知道我做错了什么。

    我想这是因为您的类路径中既有来自
    jaxrs-ri-2.12.zip的jar,也有来自
    jsr311-api-1.1.2.r612.jar的
    jsr311-api-1.1.2.r612.jar
    的JAX-RSAPI的较旧实现。您的
    应用程序
    类是
    restestapplication
    >扩展自是从
    jsr311-api-1.1.2.r612.jar
    ;但是在运行时,引用了
    jaxrs-ri-2.12.zip中jaxrs-jar的
    应用程序
    类。从WEBINF/lib中删除
    jsr311
    jar有望解决这个问题


    如果您从两个jar中反编译
    应用程序
    类,您会注意到
    jsr311
    jar中的类没有
    getProperties
    方法,因此
    java.lang.NoSuchMethodError
    错误。

    现在可以工作了。感谢您提供的解决方案以及详细的解释。
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
        <display-name>RestWS</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list> 
    <servlet>
        <servlet-name>Rest Test</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.example</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Rest Test</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>
    </web-app>`