- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) >
- SpringSecurity跳轉頁(yè)面失敗怎么辦
這篇文章主要介紹SpringSecurity跳轉頁(yè)面失敗怎么辦,文中介紹的非常詳細,具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
今天新建SpringBoot項目練手,第一次添加了Spring Security.成功啟動(dòng)項目后發(fā)現與之前新建的項目有點(diǎn)不一樣,無(wú)論我怎么設置系統首頁(yè),瀏覽器內打開(kāi)的都是登陸界面
無(wú)論我怎么設置controller的跳轉路徑都不起作用,氣到撓頭?。?!
經(jīng)過(guò)查閱各種資料發(fā)現可能是Spring Security權限控制的原因,于是著(zhù)手配置控制權限。
新建SecurityConfig類(lèi)進(jì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可以任意訪(fǎng)問(wèn) http .authorizeRequests() .antMatchers("/css/**", "/index").permitAll(); }}
一些解釋?zhuān)?/p>
authorizeRequests: 配置一些資源或者鏈接的權限認證 antMatchers:配置哪些資源或鏈接需要被認證 permitAll:設置完全允許訪(fǎng)問(wèn)的資源或者鏈接
添加上述權限設置后index頁(yè)面可以正常訪(fǎng)問(wèn)
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。
Copyright ? 2009-2021 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 珠海市特網(wǎng)科技有限公司 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站