久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實(shí)現(xiàn)

瀏覽:16日期:2023-04-22 11:58:52

一、問題描述

在 SpringBoot 中加入 SpringSecurity 中之后,靜態(tài)資源總是被過濾,導(dǎo)致界面很難看:

SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實(shí)現(xiàn)

目錄結(jié)構(gòu):

SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實(shí)現(xià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: */@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/**'); }

SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實(shí)現(xiàn)

這里一定要謹(jǐn)記,這樣配置了 configure,之后,一定要清除 target,不然是不會生效的

SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實(shí)現(xiàn)

到此這篇關(guān)于SpringBoot+SpringSecurity 不攔截靜態(tài)資源的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)SpringBoot+SpringSecurity 不攔截靜態(tài)資源內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 平利县| 天津市| 南昌县| 万州区| 建瓯市| 屏南县| 五大连池市| 布拖县| 宕昌县| 广元市| 镇平县| 宁化县| 仪征市| 方正县| 汤原县| 高陵县| 鄂伦春自治旗| 凤山市| 澄迈县| 昭苏县| 临沭县| 三江| 虞城县| 丹东市| 定结县| 尼玛县| 吉安县| 托克逊县| 白沙| 大城县| 泾川县| 保康县| 麻栗坡县| 郑州市| 曲靖市| 东兰县| 龙泉市| 依安县| 贵阳市| 喀喇沁旗| 海丰县|