首页 > 解决方案 > 如何从 webapp 文件夹而不是 spark-java 中的资源文件夹返回 `index.html`?

问题描述

我想从我的 spark-java 服务器返回 index.html。此页面位于:

src/main/webapp/portal/v1/index.html

我添加了这条路线:

get("/portal/v1/*", (req, res) -> {
  Map < String, Object > model = new HashMap <> ();
  return new VelocityTemplateEngine().render(
    new ModelAndView(model, "/portal/v1/index.html")
  );
});

当我在浏览器中打开 URL 时:http://localhost:8080/portal/v1/我收到此错误:500 Internal Server Error

在日志中,我看到了这个堆栈跟踪:

29-Mar-2021 11:58:22.038 SEVERE [http-nio-8080-exec-9] org.apache.velocity.runtime.log.JdkLogChute.log ResourceManager : unable to find resource '/portal/v1/index.html' in any resource loader.

但如果我的页面位于:src/main/resources/portal/v1/index/html此代码正常工作并返回index.html.

我试图像这样更改静态资源文件夹:

externalStaticFileLocation("src/main/webapp");
externalStaticFileLocation("/src/main/webapp");
externalStaticFileLocation("src/main/webapp/");
externalStaticFileLocation("/src/main/webapp/");

但这无济于事。

如何index.htmlwebapp文件夹而不是文件夹加载resources

标签: javaresourcesspark-java

解决方案


推荐阅读