2017-08-24 61 views
1

我有幾個不同的單頁應用程序嵌入到單個dropwizard進程中。如果我註冊了多個捆綁包,則只有最後一個捆綁包獲勝。Dropwizard多個資產包衝突

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

只提供web2。如果我反轉這些行,則只提供web1。

我該如何正確配置dropwizard,以便兩者都得到服務?

回答

1

嘗試命名的包不同:

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中解決 。

+0

是的,那可行,謝謝! –

0

Thanks @nullpointer!事實上,即使是文檔包括在這裏:

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

當AssetBundle被添加到應用程序,已被註冊爲使用資產的默認名稱的servlet。如果應用程序需要具有多個AssetBundle實例,則應使用擴展構造函數爲AssetBundle指定唯一的名稱。

正如您指出的那樣,修復就是使用第四個參數。

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