Dropwizard 多个资产包冲突

Dropwizard Multiple Asset Bundles Conflict

我有几个不同的单页应用程序要嵌入到单个 dropwizard 进程中。如果我注册了多个捆绑包,则只有最后一个捆绑包获胜。

bootstrap.addBundle(new AssetsBundle("/web1", "/web1", "index.html));
bootstrap.addBundle(new AssetsBundle("/web2", "/web2", "index.html));

仅提供 web2。如果我反转这些行,则只提供 web1。

如何正确配置 dropwizard 以便同时提供两者?

尝试以不同的方式命名这些包:

bootstrap.addBundle(new AssetsBundle("/web1", "/web1", "index.html, "asset1"));
bootstrap.addBundle(new AssetsBundle("/web2", "/web2", "index.html, "asset2"));

您正在使用的 AssetsBundle 构造函数的实现如下:

public AssetsBundle(String resourcePath, String uriPath, String indexFile) {
    this(resourcePath, uriPath, indexFile, "assets");
}

因此,您的资源包会被后一种配置覆盖。这以类似的方式解决了 在 dropwizard#499.

谢谢@nullpointer!事实上,即使是文档也在这里介绍了它:

http://www.dropwizard.io/0.9.1/docs/manual/core.html

将 AssetBundle 添加到应用程序时,它会使用默认名称资产注册为 servlet。如果应用需要有多个AssetBundle实例,应该使用扩展构造函数为AssetBundle指定一个唯一的名称。

解决方法是使用您指出的第 4 个参数。

bootstrap.addBundle(new AssetsBundle("/web1", "/web1", "index.html, "asset1"));
bootstrap.addBundle(new AssetsBundle("/web2", "/web2", "index.html, "asset2"));