springboot配置Filter的兩種方法

2021-10-24 08:40:53 字數 963 閱讀 9043

springboot配置filter的兩種方法

一、使用註解

假設filter類的路徑為com.sanro.filter

@slf4j

@webfilter

(filtername =

"authfilter"

, urlpatterns =

"/*"

)@order(1

)//測試好像這個引數不生效,實際生效的是filter掃瞄到的順序(所以起名很重要)

public

class

authfilter

implements

filter

else

}}

自動掃瞄配置如下

@slf4j

@enablescheduling

@servletcomponentscan

(basepackages =

)//這一句完成了配置,springboot的」懶理念「真的厲害。

public

class

}

二、手動配置

filter類

@slf4j

@component

public

class

authfilter

implements

filter

else

}}

filter配置類

@configuration

public

class

filterconfig

//如果有多個filter,再寫乙個public filterregistrationbean registerotherfilter()

即可。}

深入SpringBoot2 x過濾器Filter

簡介 講解springboot裡面filter講解 1.springboot啟動預設載入的filter 2.filter優先順序 ordered.highest precedence ordered.lowest precedence 低位值意味著更高的優先順序 higher values are ...

SpringBoot常用配置

前言 springboot整合了主流的第三方框架,但是需要使用springboot那一套配置方式。但是我這裡只列舉了非常非常常用的,可以看已發的幾篇部落格,慢慢會補充。當然官方文件裡也有相應的配置,可惜沒有注釋。spring.resources.cache period 設定資源的快取時效,以秒為單...

Spring boot自動配置

1 從原始碼角度看spring boot 自動配置 這個方法呼叫的是 initialize sources suppresswarnings private void initialize object sources this.webenvironment deducewebenvironment...