我使用的Spark框架在我的應用程序加載靜態文件,並使用星火不能從webjars
staticFileLocation("/META-INF/resources/");
,這樣我可以用webjars,其中包含有CSS和JS文件。我也有我自己的資源放在我的項目src/main/resources/META-INF/resources
文件夾中,因爲我的gradle build會從那裏拿起它們。
我的版本使用了fat-jar方法,其中一切都以單個jar結尾,所有文件都由Spark完美地提供。
我的問題是,當我從Eclipse單獨運行某些單元測試時,即使我確保webjars在類路徑上,但它們不是由Spark提供的,只有我自己的項目靜態資源。
@Test
public void testStartup() throws InterruptedException {
InputStream schemaIS = this.getClass().getClassLoader().getResourceAsStream("META-INF/resources/webjars/bootstrap/3.2.0/js/bootstrap.min.js");
System.out.println(schemaIS == null);
staticFileLocation("/META-INF/resources/");
// depending on the trailing/the bootstrap js is found, but Spark never serves it
}
我認爲這與類加載器有關,但我沒有找到使這項工作的方法。看看星火代碼,它說The thread context class loader will be used for loading the resource.
我也看到代碼本身刪除了尾部的斜槓,這使得在普通的getResourceAsStream
中有很大的區別。
這是Spark中的一個錯誤,還是有什麼辦法可以使它正常工作?