新聞中心
這篇文章主要介紹SpringSecurity跳轉(zhuǎn)頁面失敗怎么辦,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
專注于為中小企業(yè)提供成都網(wǎng)站設計、成都做網(wǎng)站服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)余干免費做網(wǎng)站提供優(yōu)質(zhì)的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
今天新建SpringBoot項目練手,第一次添加了Spring Security.成功啟動項目后發(fā)現(xiàn)與之前新建的項目有點不一樣,無論我怎么設置系統(tǒng)首頁,瀏覽器內(nèi)打開的都是登陸界面
無論我怎么設置controller的跳轉(zhuǎn)路徑都不起作用,氣到撓頭?。?!
經(jīng)過查閱各種資料發(fā)現(xiàn)可能是Spring Security權(quán)限控制的原因,于是著手配置控制權(quán)限。
新建SecurityConfig類進行權(quán)限配置,代碼如下:
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: 配置一些資源或者鏈接的權(quán)限認證 antMatchers:配置哪些資源或鏈接需要被認證 permitAll:設置完全允許訪問的資源或者鏈接
添加上述權(quán)限設置后index頁面可以正常訪問
以上是“SpringSecurity跳轉(zhuǎn)頁面失敗怎么辦”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
新聞標題:SpringSecurity跳轉(zhuǎn)頁面失敗怎么辦
地址分享:http://fisionsoft.com.cn/article/jhdsgj.html