Dropwizard 0.8.0:提供静态资产来自/

Bas*_*ian 4 assets path dropwizard

我希望我的服务器提供静态html文件/.此外,CSS和JS文件应该从送达/css分别/js.所有json数据都应该可以访问/api.

但是,我得到404 http://localhost:8080/或其他任何路径.

我在配置文件中使用以下设置:

server:
  type: simple
  rootPath: /api/*
Run Code Online (Sandbox Code Playgroud)

application.initialize方法如下所示:

@Override
public void initialize(io.dropwizard.setup.Bootstrap<MyConfiguration> bootstrap) {
    bootstrap.addBundle(new AssetsBundle("/assets/css", "/css", null, "css"));
    bootstrap.addBundle(new AssetsBundle("/assets/js", "/js", null, "js"));
    bootstrap.addBundle(new AssetsBundle("/assets/pages", "/", "index.html", "html"));
}
Run Code Online (Sandbox Code Playgroud)

Edd*_*Edd 6

我只需要解决类似的问题(文档不是最清楚的,虽然事后我猜大多数信息都在某处),我通过在应用程序配置中设置applicationContextPath和解决了这个问题rootPath:

server:
  type: simple
  rootPath: /api/*
  applicationContextPath: /
Run Code Online (Sandbox Code Playgroud)

默认值applicationContextPath是" /application",在一个简单的服务器,让你完整的根路径将是" /application/api/*".如果您不需要使用简单服务器,则可以使用默认服务器,默认情况下将applicationContextPath设置为" /":

server:
  rootPath: /api/*
Run Code Online (Sandbox Code Playgroud)