有关如何集成Jetty和RESTEasy的任何链接?我有点卡住尝试与Jetty一起配置RESTEasy ....而且似乎没有可靠的网络帮助 .
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
context.setDescriptor("../WEB-INF/web.xml");
context.setResourceBase("../src/webapp");
context.setContextPath("/");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
server.join();
}
我的Web.xml直接从以下位置复制:http://docs.jboss.org/resteasy/docs/1.0.0.GA/userguide/html/Installation_Configuration.html
当我尝试在资源文件中打开一个链接时,我得到的错误是HTTP 404 . 从表面上看,一切看起来都合理,有什么建议吗?
我的资源文件如下:
package webapp;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@Path("/*")
public class Resource {
@GET
public String hello() {
return "hello";
}
@GET
@Path("/books")
public String getBooks() {
return "books";
}
@GET
@Path("/book/{isbn}")
public String getBook(@PathParam("isbn") String id) {
return "11123";
}
}
这是我在Jetty启动时看到的打印件:
2012-04-10 09:54:27.163:INFO:oejs.Server:jetty-8.1.1.v20120215 2012-04-10 09:54:27.288:INFO:oejw.StandardDescriptorProcessor:没有JSP支持/,没找到org.apache.jasper.servlet.JspServlet 2012-04-10 09:54:27.319:INFO:oejsh.ContextHandler:started oejwWebAppContext {/,file:/ C:/ Users / xyz / Anotherproj1 / src / webapp} 2012- 04-10 09:54:27.319:INFO:oejsh.ContextHandler:启动oejwWebAppContext {/,file:/ C:/ Users / xyz / Anotherproj1 / src / webapp} 2012-04-10 09:54:27.381:INFO: oejs.AbstractConnector:已启动SelectChannelConnector@0.0.0.0:8080
3 回答
以下对我有用:
web.xml中:
同
资源
和主类
你确定@Path(“/ ”)是正确的路径吗?试试@Path(“/”)也许这个是个问题 . 据我所知,路径表达式不接受正则表达式 .
编辑
我错了,你可以在@Path中使用regexps,至少RESTEasy supports that .
要让RESTEasy和Jetty一起工作 without web.xml确保您在pom.xml中依赖resteasy-servlet-initializer .
这可能会有所帮助(JBoss RESTEasy文档):https://docs.jboss.org/resteasy/docs/3.0.4.Final/userguide/html/Installation_Configuration.html#d4e111