LoginSignup
4
0

More than 3 years have passed since last update.

Spring Security loginページにcss適用できない(MIME type ('text/html') is not a supported...)

Last updated at Posted at 2020-05-23

Spring Securityを使用してloginページでcssを適用とした際に以下エラーが発生

console
Refused to apply style from 'http://localhost:8080/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
login.html
<!DOCTYPE html>
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <link th:href="@{/css/public/login.css}" rel="stylesheet" />

type="text/css"は不要だが念のため指定したりしても変化なし。
パスのエラーでもない。(ファイル名が間違っていてもこのエラーは出ます)
と少し悩んでいたところ・・・・

結論

Spring Securityでアクセス制限の対象になっていた。
セキュリティ対象外に追加してあげるとうまくいく。

SecurityConfig.kt
@Configuration
@EnableWebSecurity
class SecurityConfig : WebSecurityConfigurerAdapter() {

    override fun configure(web: WebSecurity) {

        // セキュリティ設定無視の設定
        web.ignoring().antMatchers(
                "/images/**",
                "/css/**"  // ←これを追加して解決
        )
    }
4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0