idea springboot woff/woff2/eot/ttf/svg等小图标不显示的问题 - 第515篇

历史文章(文章累计500+)

国内最全的Spring Boot系列之一

国内最全的Spring Boot系列之二

国内最全的Spring Boot系列之三

国内最全的Spring Boot系列之四

国内最全的Spring Boot系列之五》

国内最全的Spring Boot系列之六

国内最全的Spring Boot系列之七》

抖音主播/电商人员有福了,利用Suno创作产品宣传,让产品动起来-小米Su7 - 第510篇

Spring Boot整合ElasticSearch实战 - 第511篇

Transaction rolled back because it has been marked as - 第512篇

五音不全也浪漫,521清华学霸为爱人写歌 - 第513篇

一文讲清楚SpringBoot项目打包jar后运行报错template might not exist - 第514篇

悟纤:师傅,师傅,呼叫师傅~

师傅:徒儿又是怎么了?

悟纤:徒儿这又掉进坑里了。

师傅:爬起来不就完事了嘛~

悟纤:师傅,这个技术坑的掉进去,可不好爬出来。

师傅:那为师这就拉你一把。

悟纤:师傅赶紧的,不然徒儿要掉进无尽深渊了~

导读

最近在开发一个AI导航项目(地址在下面)的时候,遇到了springboot woff/woff2/eot/ttf/svg等小图标不显示的问题。

正常的CSS、js、img文件是可以访问的。

项目地址:http://ai.dzwlai.com/

AI导航站,汇总**800+**工具集合:

出现情况

在idea开发工具总,使用SpringBoot框架进行开发,当在css文件中使用到woff/woff2/eot/ttf/svg等小图标的时候,无法正常显示。

解决方法

情况1:资源文件未正常导入

需要在pom文件的build中加入以下代码:

<resources>    <resource>        <directory>${project.basedir}/src/main/resources</directory>        <filtering>true</filtering>        <excludes>            <exclude>static/**</exclude>        </excludes>    </resource>    <resource>        <directory>${project.basedir}/src/main/resources</directory>        <filtering>false</filtering>        <includes>            <include>static/**</include>        </includes>    </resource></resources><plugins>    <plugin>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-maven-plugin</artifactId>        <configuration>            <source>1.8</source>            <target>1.8</target>            <encoding>UTF-8</encoding>            <compilerArguments>                <extdirs>${project.basedir}/libs</extdirs>            </compilerArguments>            <includeSystemScope>true</includeSystemScope>        </configuration>    </plugin>    <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-resources-plugin</artifactId>        <configuration>            <nonFilteredFileExtensions>                <nonFilteredFileExtension>woff</nonFilteredFileExtension>                <nonFilteredFileExtension>woff2</nonFilteredFileExtension>                <nonFilteredFileExtension>eot</nonFilteredFileExtension>                <nonFilteredFileExtension>ttf</nonFilteredFileExtension>                <nonFilteredFileExtension>svg</nonFilteredFileExtension>            </nonFilteredFileExtensions>        </configuration>    </plugin></plugins>​

情况2:被拦截了

如果你的框架使用了一些权限框架,比如Spring Security,那么可能是某些后缀文件呗拦截了,需要配置放行。

放行的代码如下:

.antMatchers(HttpMethod.GET, "/**/*.woff","/**/*.woff2","/**/*.eot","/**/*.ttf","/**/*.svg").permitAll()

我的情况

我这里是情况2,被拦截掉了。所以在配置文件中SecurityConfig进行了如下的配置:

httpSecurity......        /// 过滤请求        .authorizeRequests()        // 对于登录login 注册register 验证码captchaImage 允许匿名访问        .antMatchers("/login", "/register").permitAll()        .antMatchers(HttpMethod.GET, "/**/*.woff","/**/*.woff2","/**/*.eot","/**/*.ttf","/**/*.svg").permitAll()        // 除上面外的所有请求全部需要鉴权认证        .anyRequest().authenticated()        .and()        .headers().frameOptions().disable();​

👉 🏻 👉 🏻 👉 🏻 最后大家可以收藏一下网址:

http://ai.dzwlai.com/

**800+**工具集合总有一个你能用到的~

相关推荐
南宫生2 小时前
力扣每日一题【算法学习day.132】
java·学习·算法·leetcode
计算机毕设定制辅导-无忧学长2 小时前
Maven 基础环境搭建与配置(一)
java·maven
bing_1582 小时前
简单工厂模式 (Simple Factory Pattern) 在Spring Boot 中的应用
spring boot·后端·简单工厂模式
天上掉下来个程小白3 小时前
案例-14.文件上传-简介
数据库·spring boot·后端·mybatis·状态模式
风与沙的较量丶3 小时前
Java中的局部变量和成员变量在内存中的位置
java·开发语言
m0_748251723 小时前
SpringBoot3 升级介绍
java
极客先躯4 小时前
说说高级java每日一道面试题-2025年2月13日-数据库篇-请说说 MySQL 数据库的锁 ?
java·数据库·mysql·数据库的锁·模式分·粒度分·属性分
程序员侠客行4 小时前
Spring事务原理 二
java·后端·spring
小猫猫猫◍˃ᵕ˂◍5 小时前
备忘录模式:快速恢复原始数据
android·java·备忘录模式
liuyuzhongcc5 小时前
List 接口中的 sort 和 forEach 方法
java·数据结构·python·list