Add external resources folder to Spring Boot

Your second approach would work:

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**")
            .addResourceLocations("/resources/", "file:resources/");
}

but only if you launched Spring Boot from /Directory, because file:resources/ is a relative path.

cd Directory
java -jar Application.jar

It's nice if you can pack everything into the jar, but if you have to reference external resources, you should use absolute paths to avoid problems like this.


 @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry
            .addResourceHandler("/files/**")
            .addResourceLocations("file:/location1/", "file:/location2/");
}

access file using http://localhost:{port}/files/image.png