SpringBoot 静态资源 加载位置

1、配置自定义拦截器

/**
 * Copyright (C), 2017-2018, XXX有限公司
 * FileName: WebConfig
 * Author:   丶Zh1Guo
 * Date:     2018/11/22 16:34
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.example.demo.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 〈一句话功能简述〉<br>
 * 〈配置静态资源路径〉
 *
 * @author 丶Zh1Guo
 * @create 2018/11/22
 * @since 1.0.0
 */

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/");
        registry.addResourceHandler("/static").addResourceLocations("classpath:/static");
    }
}

2、application.yml 文件配置

resources:
    static-locations: classpath:/static,classpath:/public,classpath:/resources,classpath:/META-INF/resources

3、引用如下../static/

猜你喜欢

转载自www.cnblogs.com/it-noob/p/10002265.html