【发布时间】:2021-10-11 22:46:29
【问题描述】:
我有一个 Spring Boot 应用程序,它只有一个 HTML 页面,允许用户上传图像,另一个页面可以查看上传的图像。
这是我的项目结构:
我的 Windows 计算机工作正常,然后我在运行 Spring Boot 应用程序的 Ubuntu 服务器上创建了一个服务,这里的图像上传工作正常,但在另一个 HTML 页面上,图像没有显示并显示如下:
我试图停止服务并重新启动它并且图像正确显示! 所以在运行时看不到新图像,但是当我重新启动它时,图像会出现。
我该如何解决这个问题?
这是我的网络配置:
@Configuration
public class WebConfiguration extends WebMvcConfigurationSupport {
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/");
}
}
这是我的图像保护程序:
public static void saveFile(String uploadDirImg, String fileName, MultipartFile image) throws IOException {
Path pathForSavingImg = Paths.get("src", "main", "resources", "static", "db_images");
Path filePath = pathForSavingImg.resolve(fileName);
image.transferTo(filePath);
}
【问题讨论】:
标签: java spring spring-boot tomcat thymeleaf