SpringSecurity跳转页面失败怎么办

发布时间:2021-09-27 17:50 来源:亿速云 阅读:0 作者:小新 栏目: 开发技术

这篇文章主要介绍SpringSecurity跳转页面失败怎么办,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

今天新建SpringBoot项目练手,第一次添加了Spring Security.成功启动项目后发现与之前新建的项目有点不一样,无论我怎么设置系统首页,浏览器内打开的都是登陆界面

无论我怎么设置controller的跳转路径都不起作用,气到挠头!!!

经过查阅各种资料发现可能是Spring Security权限控制的原因,于是着手配置控制权限。

新建SecurityConfig类进行权限配置,代码如下:

import org.springframework.context.annotation.Bean;import org.springframework.security.config.annotation.web.builders.HttpSecurity;import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;import org.springframework.security.crypto.password.NoOpPasswordEncoder;@EnableWebSecuritypublic class SecurityConfig extends WebSecurityConfigurerAdapter {  @Override  protected void configure(HttpSecurity http) throws Exception {    //配置资源文件,其中/css/**、index可以任意访问    http        .authorizeRequests()        .antMatchers("/css/**", "/index").permitAll();  }}

一些解释:

authorizeRequests: 配置一些资源或者链接的权限认证  antMatchers:配置哪些资源或链接需要被认证  permitAll:设置完全允许访问的资源或者链接

添加上述权限设置后index页面可以正常访问

免责声明:本站发布的内容(图片、视频和文字)以原创、来自互联网转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系QQ:712375056 进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。