html - CSS 和图像未在 Spring Boot 的 index.html 中加载
问题描述
我的文件是这样组织的:
index.html
通过 Intellij 的午餐 url ( localhost:63342/../static/index.html
)访问时完美呈现
但是当我运行我的 Spring Boot 应用程序并访问http://localhost:8080/
时,我index.html
无法加载 CSS 文件和图像。
我没有触及任何其他配置。我所有的控制器都是@RestController
s。我确实已mustache
作为依赖项安装,但没有在任何地方使用它。
index.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Project</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link rel="stylesheet" type="text/css" href="css/body.css"/>
<link rel="stylesheet" type="text/css" href="css/header.css"/>
<link rel="stylesheet" type="text/css" href="css/section_one.css"/>
<link rel="stylesheet" type="text/css" href="css/section_two.css"/>
</head>
<body class="body-inner-wrap">
<header>
<div id="header-wrapper">
<div id="title" class="main_title">
<h1>Project</h1>
</div>
<div id="links">
<ul>
<li>
<a href="#Join"><b>Join</b></a>
</li>
<li>
<a href="#Howto"><b>How-To</b></a>
</li>
<li>
<a href="#About"><b>About</b></a>
</li>
</ul>
</div>
</div>
</header>
<div id="content-wrapper">
<div id="intro-box">
<h2>A simple and fast platform to upload audio files and reach out to your listeners via
our no non-nonsense mobile apps.</h2>
<h5>This is work in progress and will be live soon as a closed beta.</h5>
</div>
<div id="login-box">
<div class="login-form">
<form method="post" action="">
<p><input type="text" name="Username" value="" required placeholder="Username"></p>
<p><input type="password" name="password" value="" required placeholder="Password"></p>
<p><input type="submit" name="Login" value="Login"></p>
</form>
</div>
</div>
</div>
<br><br>
<div id="device-mock-bg">
<div class="device-mock">
<img src="images/android-device-mock.svg"
alt="Android app mock up"
height="700"
width="300" />
</div>
</div>
</body>
</html>
另外,检查浏览器的控制台我发现了这些 -
The resource from “http://localhost:8080/css/style.css” was blocked due to MIME type (“application/json”) mismatch (X-Content-Type-Options: nosniff)
Cookie “JSESSIONID” will be soon treated as cross-site cookie against “http://localhost:8080/css/style.css” because the scheme does not match.
请问有什么帮助吗?
解决方案
问题是 Spring Security 阻塞了所有资源。必须将其配置为允许/css/*
和/images/*
推荐阅读
- javascript - Jasmine 的测试失败了
- c# - 是否可以在 Visual Studio 中连接现有的本地数据库并使用 ASP.NET mvc Core 在 Web 上生成数据?
- mysql - Heroku 部署:连接被拒绝,无法使用 JawsDB 和 MySQL 获取错误
- r - 基于列名向量缩放列
- android - 无法在 Android Studio 4.1 中打开项目结构对话框
- c++ - 如何正确结束我的鼠标记录程序
- python - 如何读取以单引号开头的列并写入其他单元格而不丢失使用 xlwings 的 Excel 单元格格式
- spring-cloud-dataflow - SCDF Stream Deployment 状态不一致
- blazor - Blazor MSAL 错误 AADSTS50058。已发送静默登录请求,但没有用户登录
- java - Java Connect4 游戏。我想检查列是否已满