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+**工具集合总有一个你能用到的~

相关推荐
小马爱打代码5 分钟前
Spring Boot - 实现邮件发送
spring boot·后端
DKPT6 分钟前
Eclipse,MyEclipse,IDEA,Vscode这些编译器和JDK的相爱相杀
java·eclipse·编辑器·intellij-idea·myeclipse
肠胃炎9 分钟前
真题246—矩阵计数
java·线性代数·算法·矩阵·深度优先
前行的小黑炭1 小时前
设计模式:为什么使用模板设计模式(不相同的步骤进行抽取,使用不同的子类实现)减少重复代码,让代码更好维护。
android·java·kotlin
Java技术小馆1 小时前
如何设计一个本地缓存
java·面试·架构
XuanXu2 小时前
Java AQS原理以及应用
java
风象南5 小时前
SpringBoot中6种自定义starter开发方法
java·spring boot·后端
mghio13 小时前
Dubbo 中的集群容错
java·微服务·dubbo
咖啡教室18 小时前
java日常开发笔记和开发问题记录
java