I have the following structure
ui
dist
index.js
backend
src
main
java
org
example
Application.java
I am trying to present index.js as a static resource. I tried the following in my application...
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/ui/*")
.addResourceLocations("file:///../ui/dist");
}
But this doesn't host the file like I would expect.
How do I host a relative file as a static resource using Spring Boot?
This worked for me...
String currentPath = new File(".").getAbsolutePath();
registry.addResourceHandler("/ui/**")
.addResourceLocations("file:///"+currentPath+"/../ui/dist/");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.