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

相关推荐
lizi8888843 分钟前
单组件的编写
java
java_heartLake1 小时前
设计模式之代理模式
java·设计模式·代理模式
魏 无羡1 小时前
pgsql 分组查询方法
java·服务器·数据库
兩尛2 小时前
java--面向对象编程(中级部分)
java·开发语言
Xxxx. .Xxxx2 小时前
C语言程序设计实验与习题指导 (第4版 )课后题-第二章+第三章
java·c语言·开发语言
姜西西_2 小时前
[Spring]Spring MVC 请求和响应及用到的注解
java·spring·mvc
逸狼2 小时前
【JavaEE初阶】多线程6(线程池\定时器)
java·开发语言·算法
qq_35323353892 小时前
【原创】java+springboot+mysql科研成果管理系统设计与实现
java·spring boot·mysql·mvc·web
dawn1912282 小时前
SpringMVC 入门案例详解
java·spring·html·mvc
极客先躯2 小时前
高级java每日一道面试题-2024年9月16日-框架篇-Spring MVC和Struts的区别是什么?
java·spring·面试·mvc·struts2·框架篇·高级java