从Dropwizard 0.7.1中的基本URL提供静态内容

时间:2014-10-28 14:11:08

标签: dropwizard

这很容易使用Dropwizard 0.6.2,但随着向0.7.x的移动,它变得非常困难。我可以让它工作,但不是完全合适的方式。我希望我的RESTful API可以在“/ api / *”点获得,而静态内容可以从根URL“/".

获得。

我目前用0.7.1获得的最佳效果是提供来自“/ api / ”的API内容,以及来自“/ api / assets / ”的静态内容。这并不可怕,但如果我能达到最初规定的目标,它会让事情变得更好。我已尝试过配置我的AssetBundle()的各种排列,尝试使用https://github.com/bazaarvoice/dropwizard-configurable-assets-bundle,尝试了我在源代码中看到的并创建自己的专用StaticAssetsBundle类,但都无济于事。

我现在正在工作(设法从“/ api / assets / *”提供静态内容)如下:

public void initialize(Bootstrap<ConfigConfiguration> bootstrap) { bootstrap.addBundle(new AssetsBundle()); }

..在我的配置文件中我有......

server: type: simple connector: type: http port: 8458 applicationContextPath: /api .....

有人可以给我一个简洁且完整的示例,说明如何从“/”获得静态内容的服务,同时仍保留我的API服务“/ api / *”?我已经进行了广泛的搜索并找到了提示,部分答案,在0.7.1中似乎不起作用的答案,并且我准备放弃并且只是从一个完全独立的服务器实例提供我的静态内容(这是可能是DW人认为我应该做的事情。)

1 个答案:

答案 0 :(得分:4)

Application中的这类内容如何:

@Override
public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
  // Static assets are in src/main/resources/assets
  bootstrap.addBundle(new AssetsBundle("/assets", "/"));
}

@Override
public void run(ExampleConfiguration configuration, Environment environment) throws Exception {
  environment.jersey().setUrlPattern("/api/*");
}
相关问题