I have this resource handler, and I am able to call the static web page located in different location, but I am trying to call from controller class I am not able to get the page
@Configuration
public class Static_ResourceHandler implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/system/files/**").addResourceLocations("file:/home/niteshb/Documents/data");
}
}
This is what I am calling
http://localhost:8080/system/files/test.html
but how to call it from controller, I was trying something like this but its not working This is my controller class call..
@GetMapping("/")
public String getfile() {
return "test.html";
}
Create a Get mapping for /system/files/
, for which you had created the resource handler, and return the file in the newly created method.
@GetMapping("/system/files/")
public String getStaticfile() {
return "/system/files/test.html";
}
Hope that should work.
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.