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

相关推荐
BD_Marathon9 分钟前
【JavaWeb】启动tomcat报错:启动子级时出错
java·tomcat
while(1){yan}11 分钟前
网络协议TCP
java·网络·网络协议·tcp/ip·青少年编程·电脑常识
IT_陈寒12 分钟前
SpringBoot 3.2 实战:用这5个新特性让你的API性能提升40%
前端·人工智能·后端
一过菜只因15 分钟前
JavaWeb后端(spring--boot)
java·开发语言
五仁火烧20 分钟前
安装rust开发环境
开发语言·后端·rust
yuyu_030424 分钟前
SOHE智能厨余垃圾处理系统
java·vue
IT枫斗者25 分钟前
Netty的原理和springboot项目整合
java·spring boot·后端·sql·科技·mysql·spring
Edward1111111128 分钟前
普通java项目转为maven项目 J文件后缀.java变C文件
java·开发语言·maven
一雨方知深秋32 分钟前
二.java程序基本语法
java·类型转换·变量·方法·运算符·字面量·关键字标识符