springboot can not access static resources

You can not access static resources under static

 

 

 1. Add in the application.yml

  resources:
    static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:./../images

 2, the configuration webconfig

  

@EnableWebMvc
@Configuration
public class WebAppConfig implements WebMvcConfigurer {

    private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
            "classpath:/META-INF/resources/", "classpath:/resources/",
            "classpath:/static/", "classpath:/public/" };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AppInterceptor()).addPathPatterns("/**").excludePathPatterns("");
    }


    @Override
    public voidaddResourceHandlers (ResourceHandlerRegistry Registry) {
         // Configure server virtual path, handler is accessed in the page directory, locations of files corresponding to the local path 
        registry.addResourceHandler ( "/ static / **" ) 
                .addResourceLocations (CLASSPATH_RESOURCE_LOCATIONS); 
    } 

}

 

ok, you can access the static resources

Guess you like

Origin www.cnblogs.com/lljh/p/11904269.html