长话短说
问题是,如果我执行类似 http://localhost:8080/registerUser
的操作,然后转到 http://localhost:8080/login
并然后我登录,它重定向到 http://localhost:8080/style.css
,但我已经把它放在 .defaultSuccessUrl("home.html")
和如果我在第一次通话时登录,它会起作用。
似乎 Spring
试图加载 css 但它没有权限或其他东西,然后当我登录时它尝试加载,然后 css 工作......
我在我的 Spring
元素上加载 css 时遇到问题,我有它:
resources/static/styles.css
如果我不添加这行代码:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**").anyRequest();
}
anyRequest()
成功了,但现在我可以像以前一样调用登录页面了
http://localhost:8080/login
此登录是 Spring
的默认形式,如果我删除 .anyRequest()
它会显示 login
但不会加载CSS。
我的全类如下:
public class BaseSecurityConfig extends WebSecurityConfigurerAdapter {
//Configure Spring security's filter chain
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**").anyRequest();
}
//Configure how requests are secured by interceptors
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
// order matters. First the most specific, last anyRequest()
.antMatchers("/static/**").permitAll()
.antMatchers("/h2-console/**").permitAll()
.mvcMatchers("/registerUser").permitAll()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.formLogin() //a login form is showed when no authenticated request
.defaultSuccessUrl("/home.html")
.and()
.httpBasic()
.and()
.rememberMe()
.tokenValiditySeconds(2419200)
.key("auctions")
.and()
.logout()
.logoutSuccessUrl("/bye.html");
http
.csrf().disable()
.headers()
.frameOptions().disable();
}
}
我错过了什么?
编辑
在我的 .html
上,我这样做:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org" xmlns:form="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" th:href="@{../style.css}"/>
<title>pewLas</title>
</head>
<body>
最佳答案
关于你的问题
I saw this post, but where do I create the css folder? which root?
请尝试“/resources/static/css/styles.css”
关于java - 未检测到登录页面 spring boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47166205/