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/

SpringBoot 静态资源 加载位置的更多相关文章
- 【Bug档案01】Spring Boot的控制器+thymeleaf模板 -使用中出现静态资源加载路径不当的问题 -解决时间:3h
总结 - thymeleaf的模板解析规则不清楚,或者忘了; - 出现bug时,瞎调试, 没有打开NETWORK 进行查看资源的加载情况 - 控制器中的其他代码,可以先注释掉,这样就可以迅速屏蔽掉其他 ...
- SpringBoot配置文件的加载位置
1.springboot启动会扫描以下位置的application.properties或者application.yml文件作为SpringBoot的默认配置文件 --file:/config/ - ...
- IDEA中Springboot静态文件加载(热部署)
Springboot项目静态文件加载 昨天写项目的时候碰到一个问题,就是静态文件css无法读取到项目中,我仔细思考了下,总结了下,可能有两个问题 1.页面未加载更新 这个可能性非常大,Chrome就是 ...
- Springboot中jar 重复冲突 导致 静态资源加载问题!
这个jar 其实在common 中也是存在的 ,当时没注意看,就导入进来了,然后 css js 等一些静态资源全部不能加载!具体原因我没去深挖!后面找个时间深挖下,先填坑!
- Springboot:静态资源加载(七)
WebMvc自动配置: 搜索WebMvcAutoConfiguration自动装配类: 第一种方式通过webjars加载静态资源: https://www.webjars.org(通过maven加载依 ...
- SpringMvc静态资源加载出错
使用mvc:resource配置 web.xml配置是rest风格的/ 服务器启动没问题 访问地址是报404 另外用了default-servlet的方法加载,服务器启动没错,jsp页面加载静态资源要 ...
- springMVC servlet 静态资源加载
问题描述 新手使用SpringMVC时市场会遇到静态资源无法加载在问题,如下图所示 问题原因 出现这种问题一般是在web.xml中的对spring的DispatcherServlet采用了如下配置,即 ...
- 关于web项目中静态资源加载不了的一些解决思路
问题的产生: <!--springMVC前端控制器加载--> <servlet> <servlet-name>springmvc</servlet-name& ...
- spring boot的静态资源加载
1.spring boot默认资源处理 Spring Boot 默认为我们提供了静态资源处理,使用 WebMvcAutoConfiguration 中的配置各种属性. spring boot默认加载文 ...
随机推荐
- vim 插件之NERD tree
NERD tree 这个插件可以用来快速浏览目录结构,打开文件 地址 http://www.vim.org/scripts/script.php?script_id=1658 https://gith ...
- poj--2385--Apple Catching(状态dp)
Apple Catching Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submi ...
- sicily 1031 Campus(图算法)
Description At present, Zhongshan University has 4 campuses with a total area of 6.17 square kilomet ...
- Failed to start metasploit.service: Unit metasploit.service not found的解释
不多说,直接上干货! root@kali:~# service metasploit start Failed to start metasploit.service: Unit metasploit ...
- java9新特性-6-多版本兼容jar包
1.官方Feature 238: Multi-Release JAR Files 2.使用说明 当一个新版本的Java出现的时候,你的库用户要花费数年时间才会切换到这个新的版本.这就意味着库得去向后兼 ...
- HDU 2515 Yanghee 的算术【找规律】
题意:中文的题目 找规律可以发现 sum[1]=a[1]+a[2] sum[2]=a[1]+a[3] sum[n]=a[2]+a[3] 解出a[1],就可以求出其他的了 #include<ios ...
- C#线程安全打开/保存文件对话框
在多线程单元模式(MTA)中为应用程序使用.NET OpenFileDialog和SaveFileDialog 下载FileDialogsThreadAppartmentSafe_v1.zip 如果您 ...
- 通过.ENV文件来配置ThinkPHP的数据库连接信息
在ThinkPHP系统根目录创建.env文件,注意WINDOWS无法直接右键创建,使用编辑器保存时设置文件名为.env就可以创建文件.内容如下: .evn文件内容如下: [database] host ...
- zabbix4.0 使用nginx前端安装
注:环境需求:centos7 1.安装阿里云yum源: rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/4.1/rhel/7/x86_64/zabb ...
- 【redis】redis命令集
参考资料: http://www.cnblogs.com/woshimrf/p/5198361.html