I have some files under the static folder. And after I deploy another version of war all my files under static folder get lost. Tomcat automatically removes the folder. Is there any way around to save the file?
I also try to build a project using springboot and make the static folder just outside the project. But I am unable to do that.
@Configuration
public class WebConfiguration extends WebMvcConfigurationSupport {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String path = this.getClass().getClassLoader().getResource("").getPath();
String fullPath="";
try {
fullPath = URLDecoder.decode(path, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String pathArr[] = fullPath.split("jobportal/WEB-INF/classes/");
File directory = new File(pathArr[0].concat("uploads"));
if (!directory.exists()) {
directory.mkdir();
}
String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/",directory.getAbsolutePath()};
registry.addResourceHandler("/**")
.addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
I have been using the above configurations. I am only able to serve static files inside the project not outside. Please Help.