springboot访问静态资源遇到的坑


开始是以这种结构进行的,结果页面上一篇红,访问的页面是这样的

最终找出来问题,虽然每次调整路径都不对,最终查看多种方法可以看到了:

增加:

package com.example.demo.config;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;



@Component
public class WebConfig implements WebMvcConfigurer {
/*
     * 添加静态资源文件,外部可以直接访问地址
     *
     * @param registry
     */

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

这样就可以地方问到了:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM