[英]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.