我使用的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中的一个错误,还是有什么办法可以使它正常工作?