您好,登錄后才能下訂單哦!
這篇文章主要介紹了Spring Security跳轉(zhuǎn)頁面失敗問題解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
今天新建SpringBoot項(xiàng)目練手,第一次添加了Spring Security.成功啟動(dòng)項(xiàng)目后發(fā)現(xiàn)與之前新建的項(xiàng)目有點(diǎn)不一樣,無論我怎么設(shè)置系統(tǒng)首頁,瀏覽器內(nèi)打開的都是登陸界面,如圖:
無論我怎么設(shè)置controller的跳轉(zhuǎn)路徑都不起作用,氣到撓頭!?。?/p>
經(jīng)過查閱各種資料發(fā)現(xiàn)可能是Spring Security權(quán)限控制的原因,于是著手配置控制權(quán)限。
新建SecurityConfig類進(jìn)行權(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; @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { //配置資源文件,其中/css/**、index可以任意訪問 http .authorizeRequests() .antMatchers("/css/**", "/index").permitAll(); } }
一些解釋:
添加上述權(quán)限設(shè)置后index頁面可以正常訪問
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。