【发布时间】:2016-05-12 20:06:52
【问题描述】:
我正在使用 Grizzly 为我的 REST 服务提供服务,该服务可以有多个“模块”。我希望能够为服务和静态内容使用相同的基本 URL,这样我就可以访问所有这些 url:
- http://host:port/index.html
- http://host:port/module1/index.html
- http://host:port/module1/resource
- http://host:port/module2/index.html
- http://host:port/module2/resource
我尝试设置的代码如下所示:
private HttpServer createServer(String host, int port, ResourceConfig config)
{
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create("http://" + host + ":" + port + "/"), config, false);
HttpHandler httpHandler = new CLStaticHttpHandler(HttpServer.class.getClassLoader(), "docs/");
server.getServerConfiguration().addHttpHandler(httpHandler, "/");
return server;
}
使用此代码,我只能看到 html 页面,当我尝试获取资源时,我会收到“路径标识的资源不存在”响应。 当我注释掉添加 HttpHandler 的代码时,我就可以访问我的资源(但当然没有文档)。 我需要做什么才能同时访问我的资源和静态内容?
【问题讨论】:
标签: java rest jersey jax-rs grizzly