The page cannot be displayed after the SpringBoot image is uploaded, you need to restart the server

1. Phenomenon: The returned URL cannot be displayed and the error 404 is displayed, but the naming has been written, but click the idea, the uploaded image is loaded in the target, and the image can be loaded by refreshing the page.

2. Reason: The file is written to the project directory, and hot deployment is turned on, but the file is written to the project static directory, but the target is not loaded, and then click on idea, the hot deployment starts loading and just wrote File, and then refresh the page to view

3. Solution: You need to configure the mapping of the file path, change the location of the written file, do not write to the project directory with a relative path. Instead, write the file to an absolute path, and then add the mapping, whether it is linux or windows is possible

4. Code, just add the mapped configuration class


@Configuration
public class MyWebAppConfigurer implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**").addResourceLocations("file:F:/images/");
    }
}

Published 25 original articles · praised 4 · visits 1516

Guess you like

Origin blog.csdn.net/weixin_39025362/article/details/105513766