我目前正在根据路径“/”在Dropwizard中提供静态html页面。到目前为止,我只收到一个错误页面,指出“HTTP错误404问题访问/。原因:未找到”。
我跟着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;我希望它能在root用户服务,因为我的所有服务都使用了路径/ profile / v1。这被要求帮助建立DNS。
对代码进行几次修改后,将其恢复到工作状态。
assets
目录位于${Project Root}/src/main/resources
目录
bootstrap.addBundle(new AssetsBundle("/assets/", "/"));
environment.jersey().setUrlPattern("/*"); /*this line should be removed*/
您需要将dropwizard-assets
包含在项目的依赖项中。
作为参考,刚刚用静态资产创建了一个sample project。