springbot项目中使用spring security对用户身份进行认证通过之后,跳转到默认页面,默认页面中有子页面,子页面显示localhost拒绝访问问题,但是请求响应是200,直接访问这个页面也没问题,也排除了跨域问题,就是访问不到这个子页面的就是浏览器的安全策略导致的。此时可以尝试在 Spring Security 配置文件中添加以下配置:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.headers() // 添加 headers 配置
.frameOptions().disable() // 禁用 X-Frame-Options
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/home")
.permitAll()
.and()
.logout()
.permitAll();
}
}
ps:这个问题困扰了我很久,在百度上面也搜了很多答案对我来说都无法解决,最后还是问的chatgpt,不得不说是真的好用,一下就解决了。