SpringBoot项目访问resources下的静态资源

1.新建一个配置文件夹,放配置类

2.编辑

复制代码
WebMvcConfig.java
java 复制代码
package com.southwind.configuration;


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

//配置为配置类注解
@Configuration                    //继承WebMvcConfigurationSupport
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
                                               //访问路径                           //资源路径
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
    }
}

3.重启tomcat

相关推荐
云技纵横1 分钟前
一个 @Async,把 @Transactional 的事务边界打穿了
后端·面试
NE_STOP12 分钟前
Vibe Coding -- 完整项目案例实操
java
BothSavage16 分钟前
OpenHarness源码研究-3-codex配置到输出对话
后端·架构
荣码18 分钟前
GraphRAG:普通RAG只能回答"点"的问题,我踩了4个坑才搞懂
java·python
SimonKing19 分钟前
Google第三方授权登录
java·后端·程序员
codingWhat22 分钟前
能效平台设计方案(打通gitlab和飞书)
后端·node.js·koa
宋均浩24 分钟前
# REST 的四个成熟度等级:为什么你不需要 Level 3
后端
明月光81825 分钟前
从一行 @Builder 说起:重新拾起 Java 的 Lombok、注解与 Builder 模式
java
万少30 分钟前
22 点后,我靠这个 AI 工具成了"夜间天才程序员"
前端·后端
IT_陈寒1 小时前
React hooks 闭包陷阱把我的状态吃掉了,原来问题出在这里
前端·人工智能·后端