SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實現(xiàn)
一、問題描述
在 SpringBoot 中加入 SpringSecurity 中之后,靜態(tài)資源總是被過濾,導致界面很難看:
目錄結(jié)構(gòu):
二、問題解決
正常不攔截資源,我查閱資料,基本都是重新 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)存中進行配置 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)的頁面統(tǒng)統(tǒng)放行 .and() .csrf().disable() ; } }
常規(guī)方法是:
@Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers("/js/**", "/css/**","/images/**"); }
這里一定要謹記,這樣配置了 configure,之后,一定要清除 target,不然是不會生效的
到此這篇關(guān)于SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實現(xiàn)的文章就介紹到這了,更多相關(guān)SpringBoot+SpringSecurity 不攔截靜態(tài)資源內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決Mybatis中foreach嵌套使用if標簽對象取值的問題
這篇文章主要介紹了解決Mybatis中foreach嵌套使用if標簽對象取值的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-02-02Spring?Boot?使用?SSE?方式向前端推送數(shù)據(jù)詳解
這篇文章主要介紹了Spring?Boot?使用SSE方式向前端推送數(shù)據(jù)詳解,SSE簡單的來說就是服務器主動向前端推送數(shù)據(jù)的一種技術(shù),它是單向的,也就是說前端是不能向服務器發(fā)送數(shù)據(jù)的2022-08-08Java使用JavaMail API發(fā)送和接收郵件的代碼示例
JavaMail是Oracle甲骨文開發(fā)的Java郵件類API,支持多種郵件協(xié)議,這里我們就來看一下Java使用JavaMail API發(fā)送和接收郵件的代碼示例2016-06-06SpringBoot生成PDF的五種實現(xiàn)方法總結(jié)
這篇文章主要介紹了SpringBoot生成PDF的五種實現(xiàn)方法,在開發(fā)中經(jīng)常會遇到需要進行對一些數(shù)據(jù)進行動態(tài)導出PDF文件,然后讓用戶自己選擇是否需要打印出來,這篇文章我們來介紹五種實現(xiàn)方法,需要的朋友可以參考下2024-10-10