java - 在 jersey 2.x 中,我收到类似 java.util.concurrent.ExecutionException 的错误

标签 java rest tomcat jersey jersey-2.0

  1. 我已经使用了 jaxrs 的 jersey 实现,但是我无法执行下面的程序,如果我遇到问题任何想法都可以帮助我

    在下面的程序中,我使用了 jaxrs 的 jersy 2.x 实现 我使用 jax-rs(restfull) 的 jersey implemetation 实现了这个程序 我写了 2 个类而不是我使用的 web.xml

    我的资源.java

    package com.rest.application;
    
    import java.util.HashSet;
    import java.util.Set;
    
    import javax.ws.rs.ApplicationPath;
    
    import com.rest.webservice.SampleService;
    @ApplicationPath("rest")
    public class MyResource {
        private Set s;
        public MyResource() {
            s=new HashSet();
            s.add(new SampleService());
        }
         public Set getSingletons() {
            return s;
        }
    }
    

    示例服务.java

    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;
    
    @Path("sample")
    public class SampleService {
        @GET
        @Produces("text/html")
        @Path("{username}")
        public String sayHello(@PathParam("username")String s) {
            return "<font color='blue' size=8>Hello:" +s+ "</font>";
        }
        @GET
        @Produces("text/plain")
        public String sayBye() {
        return "Bye";
    }
    }
    

    我添加了这个程序所需的所有 jar 我仍然遇到以下错误

    java.util.concurrent.ExecutionException:
    org.apache.catalina.LifecycleException:
    Failed to start component [StandardEngine[Catalina].
    StandardHost[localhost].StandardContext[/RestApp2]]
    Caused by: org.apache.catalina.LifecycleException:
    Failed to start component [StandardEngine[Catalina].
    StandardHost[localhost].StandardContext[/RestApp2]]
    

    就像到处都显示同样的错误

    当我将服务器 tomcat 7 更改为 6 时 它正在工作但不显示输出 有没有人知道提前谢谢你

最佳答案

This说,@ApplicationPath("rest") 只能应用于 Application 的子类。

你能分享更多关于你试图做什么以及完整的堆栈跟踪是什么吗?你在使用 web.xml 吗?

关于java - 在 jersey 2.x 中,我收到类似 java.util.concurrent.ExecutionException 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30740218/

相关文章:

javascript - Node.js 和 SSL 与 ReSTLer

java - 使用 CXF 上传多个文件和元数据

tomcat - opengrok:尝试通过外部参照打开 .cpp 文件时出现 HTTP 状态 404 -/source/s

tomcat - 坚持tomcat jndi设置

java - 在 Java 中解析之前执行点击网页元素

javax.persistence.PersistenceException : Unable to build entity manager factory org. hibernate.engine.jndi.JndiException:无法查找 JNDI 名称

java - 根据像素正确缩放 x 轴 (Java)

java - 使用 lambda 表达式将列表转为 Hashmap

facebook - 从 Facebook Graph API/用户获取 "real"配置文件 URL

tomcat - primefaces 推送在使用 AWS Tomcat7 的 Safari 中不起作用