【问题标题】:CSS files not loading in spring securityCSS文件未在spring security中加载
【发布时间】:2019-02-10 08:46:25
【问题描述】:

我是 Spring Boot 和 Spring Security 的新手。在这里,我尝试使用 thymeleaf 运行 Spring Boot Web 应用程序,但是当我尝试在未加载 CSS 的浏览器页面中点击 url 时。

在 Firefox 中显示以下警告

Strict-Transport-Security: The connection to the site is untrustworthy, so the specified header was ignored.

Loading failed for the <script> with source “https://localhost:xxxx/assets/bootstrap/js/bootstrap.min.js”.

在 Chrome 下面显示错误

Refused to apply style from 'https://localhost:xxxx/assets/dist/css/login.css' because its MIME type ('application/json') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Refused to apply style from 'https://localhost:xxxx/assets/bootstrap/css/bootstrap.min.css' because its MIME type ('application/json') is not a supported stylesheet MIME type, and strict MIME checking is enabled

我的应用程序出了什么问题。

【问题讨论】:

  • @Alien 它与我的问题无关
  • 我猜你的样式表的传递被spring security阻止了,浏览器收到了某种错误消息。尝试在浏览器中打开样式表。
  • @Flocke 在浏览器中哪里可以使用?
  • @Durga 在浏览器中打开页面,然后打开源代码视图(右键单击,类似于“源代码视图”)。在那里你会发现像

标签: spring-boot spring-security thymeleaf


【解决方案1】:

只是一个一般性提示:如果您使用的是 Eclipse 之类的 IDE,请确保您拥有相应文件夹中的所有文件,并检查代码中的文件路径。

如果您将文件从文件系统复制到项目文件夹中,您还必须刷新项目。

其次,转到您的 SecurityConfiguration 类文件并在其中添加 /assets/** 如下(如果您没有这样做):

//...Other code here
private static final String[] PUBLIC_MATCHERS = {
            "/",
//...other code ....
            "/assets/**"
    };

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests().
            antMatchers(PUBLIC_MATCHERS).
            permitAll().anyRequest().authenticated();

//other code...
}
}

如果您的情况所有这些都失败了,请尝试将 cdn 用于引导文件,请检查以下内容: Bootstrap 如果 cdn 适用于引导程序,那么您知道您的路径引用或安全配置中存在问题。

【讨论】:

    猜你喜欢
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 2018-02-28
    相关资源
    最近更新 更多