SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實(shí)現(xiàn)
一、問題描述
在 SpringBoot 中加入 SpringSecurity 中之后,靜態(tài)資源總是被過濾,導(dǎo)致界面很難看:
目錄結(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: */@Configurationpublic 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)的頁面統(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,不然是不會生效的
到此這篇關(guān)于SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)SpringBoot+SpringSecurity 不攔截靜態(tài)資源內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. ASP基礎(chǔ)入門第二篇(ASP基礎(chǔ)知識)2. 不使用XMLHttpRequest對象實(shí)現(xiàn)Ajax效果的方法小結(jié)3. python使用pywinauto驅(qū)動微信客戶端實(shí)現(xiàn)公眾號爬蟲4. Python如何解決secure_filename對中文不支持問題5. ThinkPHP6使用JWT+中間件實(shí)現(xiàn)Token驗(yàn)證實(shí)例詳解6. python使用ProjectQ生成量子算法指令集7. 怎樣打開XML文件?xml文件如何打開?8. Python使用oslo.vmware管理ESXI虛擬機(jī)的示例參考9. python 定義函數(shù) 返回值只取其中一個(gè)的實(shí)現(xiàn)10. JSP出現(xiàn)中文亂碼問題解決方法詳解
