SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實(shí)現(xiàn)
一、問(wèn)題描述
在 SpringBoot 中加入 SpringSecurity 中之后,靜態(tài)資源總是被過(guò)濾,導(dǎo)致界面很難看:
目錄結(jié)構(gòu):
二、問(wèn)題解決
正常不攔截資源,我查閱資料,基本都是重新 config 方法即可:
package org.yolo.securitylogin.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.password.NoOpPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; /** * @Auther: Yolo * @Date: 2020/9/12 13:05 * @Description: */ @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean PasswordEncoder passwordEncoder() { return NoOpPasswordEncoder.getInstance(); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { //在內(nèi)存中進(jìn)行配置 auth.inMemoryAuthentication() .withUser("yolo") .password("123").roles("admin"); } @Override public void configure(WebSecurity web) throws Exception { //web.ignoring().antMatchers("/static/js/**", "/static/css/**", "/static/images/**"); web.ignoring().antMatchers("/js/**", "/css/**","/images/**"); } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login.html") .permitAll()//跟登錄相關(guān)的頁(yè)面統(tǒng)統(tǒng)放行 .and() .csrf().disable() ; } }
常規(guī)方法是:
@Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers("/js/**", "/css/**","/images/**"); }
這里一定要謹(jǐn)記,這樣配置了 configure,之后,一定要清除 target,不然是不會(huì)生效的
到此這篇關(guān)于SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)SpringBoot+SpringSecurity 不攔截靜態(tài)資源內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
一文教會(huì)你如何搭建vue+springboot項(xiàng)目
最近在搗鼓?SpringBoot?與?Vue?整合的項(xiàng)目,所以下面這篇文章主要給大家介紹了關(guān)于如何通過(guò)一篇文章教會(huì)你搭建vue+springboot項(xiàng)目,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05解決Mybatis中foreach嵌套使用if標(biāo)簽對(duì)象取值的問(wèn)題
這篇文章主要介紹了解決Mybatis中foreach嵌套使用if標(biāo)簽對(duì)象取值的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02Nacos作為配置中心注冊(cè)監(jiān)聽(tīng)器方法
本文主要討論Nacos作為配置中心時(shí),其中配置內(nèi)容發(fā)生更改時(shí),我們的應(yīng)用程序能夠做的事。一般使用監(jiān)聽(tīng)器來(lái)實(shí)現(xiàn)這步操作,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-02-02Spring?Boot?使用?SSE?方式向前端推送數(shù)據(jù)詳解
這篇文章主要介紹了Spring?Boot?使用SSE方式向前端推送數(shù)據(jù)詳解,SSE簡(jiǎn)單的來(lái)說(shuō)就是服務(wù)器主動(dòng)向前端推送數(shù)據(jù)的一種技術(shù),它是單向的,也就是說(shuō)前端是不能向服務(wù)器發(fā)送數(shù)據(jù)的2022-08-08Java使用JavaMail API發(fā)送和接收郵件的代碼示例
JavaMail是Oracle甲骨文開(kāi)發(fā)的Java郵件類(lèi)API,支持多種郵件協(xié)議,這里我們就來(lái)看一下Java使用JavaMail API發(fā)送和接收郵件的代碼示例2016-06-06基于maven搭建一個(gè)ssm的web項(xiàng)目的詳細(xì)圖文教程
這篇文章主要介紹了基于maven搭建一個(gè)ssm的web項(xiàng)目的詳細(xì)教程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09利用javadoc注釋自動(dòng)生成Swagger注解
由于現(xiàn)在controller方法上面沒(méi)有swagger注解,只能拿到接口url地址,無(wú)法獲得接口功能描述,所以本文為大家介紹一下如何利用javadoc注釋自動(dòng)生成Swagger注解,感興趣的可以了解下2023-08-08SpringBoot生成PDF的五種實(shí)現(xiàn)方法總結(jié)
這篇文章主要介紹了SpringBoot生成PDF的五種實(shí)現(xiàn)方法,在開(kāi)發(fā)中經(jīng)常會(huì)遇到需要進(jìn)行對(duì)一些數(shù)據(jù)進(jìn)行動(dòng)態(tài)導(dǎo)出PDF文件,然后讓用戶自己選擇是否需要打印出來(lái),這篇文章我們來(lái)介紹五種實(shí)現(xiàn)方法,需要的朋友可以參考下2024-10-10