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/");
}
}

这样就可以地方问到了:

springboot访问静态资源遇到的坑的更多相关文章
- 【SpringBoot】06.SpringBoot访问静态资源
SpringBoot访问静态资源 1.SpringBoot从classpath/static的目录 目录名称必须是static 启动项目,访问http://localhost:8080/0101.jp ...
- spring-boot配置静态资源映射的坑:properties文件不能添加注释
如此博文所述,Spring Boot 对静态资源映射提供了默认配置 默认将 /** 所有访问映射到以下目录:classpath:/staticclasspath:/publicclasspath:/r ...
- Springboot访问静态资源&WebJars&图标&欢迎页面
目录 概述 1.访问WebJar资源 2.访问静态资源 3.favicon.ico图标 4.欢迎页面 概述 使用Springboot进行web开发时,boot底层实际用的就是springmvc,项目中 ...
- springboot访问静态资源404
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...
- 【使用篇二】SpringBoot访问静态资源(4)
默认的,SpringBoot会从两个地方查找静态资源: classpath/static 的目录下 ServletContext 根目录下 一.classpath/static 的目录 在类路径下常见 ...
- 02-04:springboot 访问静态资源
1.SpringBoot从classpath/static的目录下:(目录名称必须叫static,可以理解为根目录为static) 2.servletContext根目录下,进行查找: 在src/ma ...
- Springboot访问静态资源
转载 http://blog.csdn.net/catoop/article/details/50501706
- Spring Boot整合Servlet,Filter,Listener,访问静态资源
目录 Spring Boot整合Servlet(两种方式) 第一种方式(通过注解扫描方式完成Servlet组件的注册): 第二种方式(通过方法完成Servlet组件的注册) Springboot整合F ...
- SpringBoot - 搭建静态资源存储服务器
目录 前言 环境 实现效果 具体实现 文件上传 配置类 上传接口 上传实现 辅助类 实体 上传测试 文件访问 配置类 项目源码 前言 记录下SpringBoot下静态资源存储服务器的搭建. 环境 wi ...
随机推荐
- DLL卸载
[DLL卸载] 1.扫描Module.通过CreateToohelp32Snapshot.Module32First.Module32Next来完成. 2.通过FreeLibrary来卸载.通过在ke ...
- java基础之JDBC五:批处理简单示例
/** * 批处理 * 批处理跟事务不同 只是把一批sql放到一起执行 2条sql是可以一条执行成功 一条执行失败 是不可逆的 */ public class Test { public static ...
- Linux修复MBR扇区故障
给虚拟机增加一块硬盘,用于备份mbr的信息 fdisk -l 查看硬盘系统是否认识 fdisk /dev/sdb 进行分区 fdisk -l 查看分区是否出来 mkfs -t ext4 /dev/sb ...
- 345. Reverse Vowels of a String翻转字符串中的元音字母
[抄题]: Write a function that takes a string as input and reverse only the vowels of a string. Example ...
- nginx配置跨域访问
前端要在本地测试ajax接口,无法跨域访问,所以在测试环境的nginx配置了跨域支持,方法如下: 在nginx.conf文件, http块下配置 42 #support cross domain ac ...
- 30-懒省事的小明(priority_queue)
http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=55 懒省事的小明 时间限制:3000 ms | 内存限制:65535 KB 难度:3 ...
- Docker学习笔记_使用Dockerfile创建flask的一个镜像
一.实验环境 1.宿主机OS:Win10 64位 2 .虚拟机OS:Ubuntu18.04 64位 虚拟机名称:Ubuntu18VM1 虚拟机IP:192.168.8.25 3.账号:doc ...
- 如何撤回经由Outlook2016刚发出的邮件
在Outlook2016中,刚发出了一封邮件,发现有问题,想撤回,如何处理? 在对方尚未查看和接收时,可撤回. 参考步骤 1.选中这封邮件,用鼠标双击打开 2.点Move旁边的下拉按钮 3.点击&qu ...
- Spring.Web.Mvc 注入(控制器属性注入)
1.web.config配置 <?xml version="1.0" encoding="utf-8"?><!-- 有关如何配置 ASP.NE ...
- jQuery中关于toggle的使用
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>t ...