我在静态文件夹下有一些文件。在我部署了另一个版本的war之后,我在静态文件夹下的所有文件都丢失了。 Tomcat自动删除该文件夹。有什么办法可以保存文件?
我还尝试使用springboot构建项目,并将静态文件夹放在项目外部。但是我无法做到这一点。
@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/");
}
}
我一直在使用上述配置。我只能在项目内部而不是外部提供静态文件。请帮忙。