Spring boot web program static resources are placed outside the jar

The static directory of the spring boot program is in the resources / static directory by default. When it is packaged as jar, the static directory will be packaged. There will be some problems:

Looking at the official documents, you can find that static can actually be external.

Method 1: modify the configuration file directly

spring.resources.static-locations=file:///E://resources/static

Custom configuration method

@Configuration
public class StaticResourceConfiguration extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("file:/path/to/my/drop@R_229_2419@/");
    }
}

Recommended method 1 is safe and harmless

Related reading: the spring boot configuration file is placed outside the jar

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>