2014-10-28 82 views
2

使用Dropwizard 0.6.2很容易,但隨着向0.7.x的過渡,它變得更加困難。我可以讓它工作,但不是完全適合的方式。我希望我的RESTful API在「/ api/*」點可用,靜態內容可以從根URL「/」獲得。從Dropwizard中的基本URL提供靜態內容0.7.1

我現在可以用0.7.1實現的最好效果是從「/ api/」提供API內容,並從「/ api/assets/」提供靜態內容。這不是很糟糕,但如果我能達到原先規定的目標,它會讓事情變得更好。我嘗試了各種配置我的AssetBundle()的排列,嘗試過使用https://github.com/bazaarvoice/dropwizard-configurable-assets-bundle,嘗試了我在源代碼中看到的內容並創建了我自己的專用StaticAssetsBundle類,但都無濟於事。

我現在(其管理服務從我「/ API /資產/ *」靜態內容)如下有工作:

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的人認爲我應該做什麼)。

回答

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/*"); 
} 
+0

我以爲我已經試過之前,沒有成功,但肯定我重新跑了安排。起初我認爲它仍然無法正常工作,但意識到我沒有修改我的配置文件來匹配。我改變了配置來閱讀** applicationContextPath:/ **,並且上面提出的更改,以及...它工作。我現在可以從「/ api/*」服務器接收我的API,並從「/」接收我的靜態文檔。迫使我重新訪問這個方法,導致我運用找到答案所需的所有排列組合。謝謝! – dfrye 2014-10-29 17:10:21