一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - SpringBoot+SpringSecurity 不攔截靜態資源的實現

SpringBoot+SpringSecurity 不攔截靜態資源的實現

2020-09-21 00:18南淮北安 Java教程

這篇文章主要介紹了SpringBoot+SpringSecurity 不攔截靜態資源的實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

一、問題描述

在 SpringBoot 中加入 SpringSecurity 中之后,靜態資源總是被過濾,導致界面很難看:

SpringBoot+SpringSecurity 不攔截靜態資源的實現

目錄結構:

SpringBoot+SpringSecurity 不攔截靜態資源的實現

二、問題解決

正常不攔截資源,我查閱資料,基本都是重新 config 方法即可:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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 {
    //在內存中進行配置
    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()//跟登錄相關的頁面統統放行
        .and()
        .csrf().disable()
    ;
  }
}

常規方法是:

?
1
2
3
4
@Override
  public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/js/**", "/css/**","/images/**");
  }

SpringBoot+SpringSecurity 不攔截靜態資源的實現

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

SpringBoot+SpringSecurity 不攔截靜態資源的實現

到此這篇關于SpringBoot+SpringSecurity 不攔截靜態資源的實現的文章就介紹到這了,更多相關SpringBoot+SpringSecurity 不攔截靜態資源內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://blog.csdn.net/nanhuaibeian/article/details/108554515

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产一久久香蕉国产线看观看 | 小兰被扒开内裤露出p | 亚洲欧美一区二区三区在饯 | 美女一线天 | 国产伦精一区二区三区视频 | 我的家教老师在线观看 | 欧美久久久久久久一区二区三区 | youzljzljzljzlj96 | caoporen97免费公开视频 | 青青草国产青春综合久久 | 91噜噜噜噜色 | 午夜人妻理论片天堂影院 | 亚洲国产欧美在线看片 | 波多野结衣52部合集在线观看 | 亚洲天堂h| 国产麻豆精品入口在线观看 | 8插8插| 午夜伦伦电影理论片大片 | 午夜影院c绿象 | 午夜免费啪视频观看视频 | 无码射肉在线播放视频 | 黄漫免费观看 | 天天干天天色综合 | 国产播放啪视频免费视频 | 好大水好多好爽好硬好深视频 | 骚虎最新网址 | 久久艹影院 | 国产ab | 国产综合第一页 | 人人澡人 | 日本啊v在线观看 | 免费黄色小说 | 女主被男主做哭失禁高h | 国产主播精品在线 | 日本欧美不卡一区二区三区在线 | 欧美人成绝费网站色www吃脚 | 视频网站入口在线看 | wwwav在线 | 日本剧情片在线播放中文版 | 日本xxx在线观看免费播放 | 日本一区二区视频在线观看 |