资产目录中的 Dropwizard 服务目录

Dropwizard service directory inside assets directory

我有一个 Dropwizard/AngularJS 网站。我的资产来自根目录中的 AssetsBundle:

public void initialize(Bootstrap<WebsiteConfiguration> bootstrap) {
    bootstrap.addBundle(new AssetsBundle("/assets/", "/", "index.html"));
    ...
}

我想在 /services 上提供我的 REST 端点:

public void run(WebsiteConfiguration configuration, Environment environment) throws Exception {
    environment.jersey().setUrlPattern("/service");
    ...
}

根据我在其他地方看到的文档和答案,这似乎应该可行。但是,我刚刚尝试过,/service 上的所有内容都返回 404。当我通过调试器深入研究应用程序时,似乎是因为请求通过 AssetServlet,而不是通过 Jersey。

我错过了什么吗?有没有一种好的方法可以在根目录上为我的前端提供服务,在子路径上提供 REST 服务?

前段时间我也为这个问题苦恼过。对我有帮助的是将这些行添加到 app.yml 配置文件中:

server:
  type: simple
  rootPath: '/rest/*'
  applicationContextPath: /