说来也奇怪,前几天刚写完的项目 写的好好的 现在打开他就加载不了前端的静态资源了
报错No mapping for GET /css/bootstrap.css

解决方法:
新建一个配置类 ,将静态资源的路径配置一下就好了

@Configuration
public class WebConfig implements WebMvcConfigurer {

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


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);

    }

}

然后就可以正常运行了

posted on 2022-10-04 11:04  bug鸭~  阅读(1459)  评论(0编辑  收藏  举报