简体   繁体   English

码头 404 访问 / 时出现问题。 原因:未找到

[英]Jetty 404 Problem accessing /. Reason: Not Found

I'm trying to get started with Jetty but only getting 404 not found at localhost.com:8080/api, /api and /api/example.我正在尝试开始使用 Jetty,但只收到 404 not found at localhost.com:8080/api、/api 和 /api/example。

This is my main method:这是我的主要方法:

Server server = new org.eclipse.jetty.server.Server(8080);
ServletContextHandler handler = new ServletContextHandler(server, "/example");
ResourceConfig config = new ResourceConfig();
config.packages("api");
config.register(new CORSConfig());

ServletHolder holder = new ServletHolder(new ServletContainer(config));
handler.addServlet(holder, "/api/*");

try {
        server.start();
        server.join();
} finally {
        server.stop();
        server.destroy();
}

What am I doing wrong?我究竟做错了什么?

Your code creates a Server , and then a ServletContextHandler then doesn't attach them together.您的代码创建一个Server ,然后创建一个ServletContextHandler然后不将它们附加在一起。

Before server.start();server.start();

call server.setHandler(handler);调用server.setHandler(handler);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用码头在Google App Engine上部署应用程序:“ HTTP错误404 Pblm访问/。原因:未找到” - Unable to deploy app on google app engine using jetty:“HTTP ERROR 404 Pblm accessing /.Reason: not found” Restful Jetty HTTP ERROR 404 访问未找到 - Restful Jetty HTTP ERROR 404 accessing not found Jetty + Guice + Jersey在访问资源时提供404 - Jetty + Guice + Jersey gives 404 on accessing the resource 错误404:访问/WEB-INF/views/sendMessage.jsp时出现问题。 原因:未找到 - Error 404: Issue accessing /WEB-INF/views/sendMessage.jsp. Reason: Not Found 嵌入式 Jetty 中的 Web 应用程序出现错误 404 未找到 - Webapplication in Embedded Jetty getting Error 404 Not found ResourceHandler 停止托管带有 jetty 9 的文件 - 404 not found 错误(适用于 jetty 8) - ResourceHandler stop hosting files with jetty 9 - 404 not found error (works fine with jetty 8) 使用 POSTMAN 访问 Spring RestApi(找不到 404) - Accessing Spring RestApi using POSTMAN (404 not found) gwt requestbuilder尝试使用Eclipse Jetty访问xml文件时返回404 NOT_FOUND错误 - gwt requestbuilder returns 404 NOT_FOUND error while trying to access xml-file with eclipse jetty Java-访问Tomcat / Jersey URL给出404 Not Found - Java - Accessing Tomcat/Jersey url gives 404 Not Found Java HTTP 错误 404 - 码头 - Java HTTP Error 404 - Jetty
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM