java - 如何从 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.html
从webapp
文件夹而不是文件夹加载resources
?
解决方案
推荐阅读
- html - 是表单标签“
- c# - Windows UIAutomation 未检测到窗口元素
- wordpress - 当 htaccess 不起作用时,如何重定向 Wordpress 子域上的 url?
- php - Laravel 为什么 $request->user() 关系不能正常工作?
- react-native - React Native Big Calendar 的 end 属性有问题
- python - Pyinstaller:找不到模块错误(熊猫)
- python - 将字符串类型转换为对象时出错
- excel - 在列和活动应用程序中查找字符串 转到
- angular - Angular 9 组件在模块中未被识别
- javascript - aria-hidden 弹出窗口的 Javascript 问题