【发布时间】:2019-03-01 04:57:34
【问题描述】:
我目前正在处理 Dropwizard 中根路径“/”的静态 html 页面。到目前为止,我只收到一个错误页面,说明“HTTP ERROR 404 Problem访问/。原因:未找到”。
我已经按照Dropwizard documentation for 1.2.2 以及本教程here 执行此操作,对代码进行了一些更改以使我的服务正常工作。我的 .yml 文件中的根路径是 /profile/v1 以允许我的 getAll 服务工作(当我第一次启动时,我收到了一个错误,因为我有 Multiple servlets map to path /*。.yml 看起来像这样:
server:
type: simple
applicationContextPath: /
rootPath: /profile/v1
另外,我在主应用类中的初始化是:
@Override
public void initialize(final Bootstrap<AutomationConfigServiceConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/../resources", "/", "index.html"));
}
这在球衣上注册为:
environment.jersey().setUrlPattern("/*");
/resources 是我保存静态资产的目录,位于java 目录之外。
到目前为止,我已经能够让我的服务在此设置中正常工作。例如,当我转到 localhost:8080/profile/v1/name/getAll 时,我能够从数据库中检索所有名称,如果我转到 localhost:8080/profile/v1/titles/getAll,我从数据库中获取所有标题。如果我使用 localhost:8080,带或不带“/”,我只会得到一个 404 页面,说它找不到“/”。理论上,这应该很简单,所以我不确定我还应该做什么。
编辑:
当我转到 /profile/v1 时,我得到以下信息:
{
code: 404,
message: "HTTP 404 Not Found",
}
我应该提到我不希望我的 html 在这里提供;我希望它在根目录下提供服务,因为我的所有服务都使用路径 /profile/v1。这是为了帮助设置 DNS。
【问题讨论】:
-
据我了解,您的静态页面应该可以从
localhost:8080/profile/v1获得 -
这样做会产生 404 json 响应。我将编辑问题以包含此内容。
标签: java html static dropwizard serving