本文介绍了使用 spring security 和 thymeleaf 时无法加载我的 css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我在使用 spring security 和 thymeleaf 时无法加载我的 css 文件.
I am not able to load my css file while using spring security and thymeleaf.
每当我使用 rel="stylesheet" 时,它都会给我 Strict MIME enable 错误.
Whenever i use rel="stylesheet" it gives me Strict MIME enable error.
我的 css 文件在资源/静态文件夹中
My css file is in resources/static folder
我的 html 文件是资源/模板.
My html file is resources/template.
HTML 头:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Login</title>
<meta http-equiv="content-type" content="text/css; charset=UTF-8">
<script src="https://ajax.googleapis/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn/bootstrap/4.1.2/css/bootstrap.min.css"
integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"
integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<script src="https://code.jquery/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn/bootstrap/4.1.2/js/bootstrap.min.js"
integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em"
crossorigin="anonymous"></script>
<link th:href="auth.css" type="text/css" href="../static/auth.css" >
<!--<link href="../static/auth.css" type="text/css" rel="stylesheet">-->
我的 Spring 安全代码:
My Spring Security Code:
@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/css/**","/static/**", "/resources/**","/.*.css").permitAll()
.anyRequest().fullyAuthenticated()
.and()
.formLogin()
.loginPage("/login").permitAll();
}
}
推荐答案
覆盖这个方法 configure(WebSecurity web)
并修改如下代码
override this method configure(WebSecurity web)
too and modifie code like below
@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login").permitAll();
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**", "/static/**", "/css/**", "/js/**", "/images/**","/vendor/**","/fonts/**");
}
}
这篇关于使用 spring security 和 thymeleaf 时无法加载我的 css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论