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

相关推荐
一只叫煤球的猫1 小时前
【🤣离谱整活】我写了一篇程序员掉进 Java 异世界的短篇小说
java·后端·程序员
斐波娜娜1 小时前
Maven详解
java·开发语言·maven
Bug退退退1231 小时前
RabbitMQ 高级特性之事务
java·分布式·spring·rabbitmq
程序员秘密基地1 小时前
基于html,css,vue,vscode,idea,,java,springboot,mysql数据库,在线旅游,景点管理系统
java·spring boot·mysql·spring·web3
皮皮林5511 小时前
自从用了CheckStyle插件,代码写的越来越规范了....
java
小码氓1 小时前
Java填充Word模板
java·开发语言·spring·word
会飞的天明1 小时前
Java 导出word 实现饼状图导出--可编辑数据
java·word
Muxiyale1 小时前
使用spring发送邮件,部署ECS服务器
java·服务器·spring
01传说2 小时前
vue3 配置安装 pnpm 报错 已解决
java·前端·vue.js·前端框架·npm·node.js
hunzi_13 小时前
搭建商城系统
java·uni-app·php