springboot如何访问静态资源

springboot如何访问静态资源

00:00
06:23

classpath:/META-INF/resources/,

classpath:/resources/,

classpath:/static/,

classpath:/public/


src\main\resources\


source folder 资源文件夹



一、通过配置文件
spring.mvc.static-path-pattern=/** 表示所有的访问都经过静态资源路径;
spring.resources.static-locations=classpath:/testStatic/,
二、代码实现
实现类继承 WebMvcConfigurerAdapter 并重写方法 addResourceHandlers
@Configuration
public class MyWebAppConfigurer
extends WebMvcConfigurerAdapter {


@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/testStatic/**").addResourceLocations("classpath:/testStatic/");
super.addResourceHandlers(registry);
}
}



以上内容来自专辑
用户评论

    还没有评论,快来发表第一个评论!