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><htmllang="ja"xmlns:th="http://www.thymeleaf.org"><head><metacharset="UTF-8"><linkth:href="@{/css/public/login.css}"rel="stylesheet"/>type="text/css"は不要だが念のため指定したりしても変化なし。
パスのエラーでもない。と少し悩んでいたところ・・・・
結論
Spring Securityでアクセス制限の対象になっていた。
セキュリティ対象外に追加してあげるとうまくいく。
SecurityConfig.kt
@Configuration@EnableWebSecurityclassSecurityConfig:WebSecurityConfigurerAdapter(){overridefunconfigure(web:WebSecurity){// セキュリティ設定無視の設定web.ignoring().antMatchers("/images/**","/css/**"// ←これを追加して解決)}