我有以下结构
ui
dist
index.js
backend
src
main
java
org
example
Application.java
我正在尝试将index.js呈现为静态资源。我在我的应用程序中尝试了以下内容...
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/ui/*")
.addResourceLocations("file:///../ui/dist");
}
但这不会像我期望的那样托管文件。
如何使用Spring Boot将相对文件作为静态资源托管?
最佳答案
这对我有用...
String currentPath = new File(".").getAbsolutePath();
registry.addResourceHandler("/ui/**")
.addResourceLocations("file:///"+currentPath+"/../ui/dist/");
关于spring-boot - 如何使用Spring Boot从另一个文件夹加载静态资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55882143/