我目前正在处理 Dropwizard 中根路径“/”的静态 html 页面。到目前为止,我只收到一个错误页面,说明“HTTP ERROR 404 Problem访问/。原因:未找到”。
我已经按照1.2.2 的 Dropwizard 文档以及此处的本教程进行了此操作,并对代码进行了一些更改以使我的服务正常工作。我的 .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。