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. Web前端——ElementUIBacktop 显示问题

    2024-06-07 10:56:03       65 阅读
  2. 2、计划任务显示UI问题

    2024-06-07 10:56:03       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-07 10:56:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-07 10:56:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-07 10:56:03       87 阅读
  4. Python语言-面向对象

    2024-06-07 10:56:03       96 阅读

热门阅读

  1. 五八 && 领岳科技面经 2024.06.06

    2024-06-07 10:56:03       19 阅读
  2. PyTorch学习(12):PyTorch的张量相乘(torch.matmul)

    2024-06-07 10:56:03       29 阅读
  3. MySQL入门学习-内置函数.时间日期函数

    2024-06-07 10:56:03       27 阅读
  4. 个人投资理财入门

    2024-06-07 10:56:03       26 阅读