我之前看到过许多对此问题的答案,但没有一个解决方案尝试过。Springboot - 将资源解释为样式表,但使用MIME类型传输文本/ htm
我的login.css
未在我的Spring Boot应用程序中应用到login.html
。我也在使用Thymeleaf。
安全性已打开 - 但我不认为这是问题,因为在浏览器中。我没有看到一个失败加载login.css
- 只有消息:
资源解释为样式表,但使用MIME类型text/html转移:
在浏览器中进一步检查表明它正在请求text/css
,但获得text/html
响应。
的HTML:
<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatiable" content="IE-Edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="Login"/>
<title>LOGIN</title>
<!-- Latest compiled and minified CSS -->
....
<link rel="stylesheet" href="login.css" content-type="text/css"/>
为login.html
\src\main\resources\templates\login.html
路径的路径login.css
\src\main\resources\static\login.css
和公正的情况下,它是一个权限问题我把:
.antMatchers("/css/**").permitAll()
我注意到所有通过CDN交付的css都没有问题。此外浏览器正在返回login.css
和302状态码。
感谢