我已经使用了 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/