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

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 天堂在线看 | 欧美伊香蕉久久综合类网站 | 亚洲第一男人天堂 | 亚洲色欲色欲综合网站 | 免费一级黄| 啊啊啊好大视频 | 911香蕉视频 | 咪咪爱在线视频 | 久久亚洲成a人片 | 大胸纲手被羞羞漫画网站 | 爱豆传媒最新视频国产 | 私人chinese beauty | 亚洲国产精品福利片在线观看 | 亚洲欧美国产自拍 | 亚洲欧美一区二区三区不卡 | sihu国产午夜精品一区二区三区 | 日韩国产成人精品视频 | 18无删减羞羞网站动漫 | 日韩一卡2卡3卡新区网站 | 免费看黄色片网站 | 4455在线| 星空无限传媒xk8027穆娜 | 亚洲国产自 | 亚洲国产麻豆 | 人体欣赏孕妇季玥图片 | 久久精品国产只有精品 | 亚洲欧美在线免费观看 | 白鹿扒开内裤露出尿孔 | 色一情一乱一伦 | 日本片免费观看一区二区 | 亚洲国产五月综合网 | 白俄罗斯bbbsss | 九九精品99久久久香蕉 | 菠萝视频在线完整版 | 日本在线色| 太大了轻点阿受不了小说h 四色6677最新永久网站 | 精品国产乱码久久久人妻 | 精品国产无限资源免费观看 | 日韩久久综合 | 午夜私人影院在线观看 视频 | 四虎影院免费视频 |