我在Spring Boot應用程式中使用自定義過濾器,似乎有2種方法可以注冊過濾器.
–> Register the filter using the @Bean
@Bean
public Filter AuthenticationFilter() {
return new AuthenticationFilter();
}
–> Anotate the Filter using @Component
@Component
public class AuthenticationFilter implements Filter {}
我很困惑的是,差異是什么以及為什么我應該使用一個而不是另一個?
uj5u.com熱心網友回復:
這在很大程度上取決于個人偏好.使用@Component需要啟用組件掃描.有些人不喜歡使用組件掃描,因為他們發現很難確定你的豆子來自哪里.使用@Bean方法宣告所有內容可以避免這種情況,但代價是撰寫(略微)更多的Java配置.
使用@Bean的另一個原因是您可能無法控制Filter的源,即您無法使用@Component對其進行注釋,因此使用@Bean方法宣告它是您唯一的選擇.
uj5u.com熱心網友回復:
maven springboot的攔截器我真的不懂啊 各位大佬有沒有明白的 指點一下轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/139314.html
標籤:其他技術討論專區
上一篇:sitemapx制作網站地圖,抓爬之后網站的鏈接少于現實存在的鏈接
下一篇:-1.1的原碼,反碼,補碼是什么
