Spring Boot 访问不到static下的js,css等静态资源
作者:互联网
解决:实现WebMvcConfigurer配置接口的addResourceHandlers方法,为静态资源添加项目路径,解决404问题
// 需添加Configuration注解
package config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyInterceptorCfg implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/community/**").addResourceLocations("classpath:/community/");
}
}
//引用静态资源
<link rel="stylesheet" th:href="@{/css/global.css}" />
引用:
Spring Boot 配置接口 WebMvcConfigurer
标签:Spring,Boot,springframework,js,import,WebMvcConfigurer,org,Configuration,config 来源: https://blog.csdn.net/xiedongze__/article/details/113422825