- Spring Boot 2.0 Cookbook(Second Edition)
- Alex Antonov
- 282字
- 2021-06-24 19:24:41
How it works...
The magic behind this functionality is actually very simple. Let's start from the separate configuration class and work our way to the filter bean detection.
If we look in our main class, BookPubApplication, we will see that it is annotated with @SpringBootApplication, which in turn is a convenience meta-annotation that declares @ComponentScan among others. We discussed this in detail in one of our earlier recipes. The presence of @ComponentScan instructs Spring Boot to detect WebConfiguration as a @Configuration class and add its definitions to the context. So, anything that we will declare in WebConfiguration is as good as if we were to put it right in BookPubApplication itself.
The @BeanpublicRemoteIpFilterremoteIpFilter() {...} declaration simply creates a Spring bean for the RemoteIpFilter class. When Spring Boot detects all the beans of javax.servlet.Filter, it will add them to the filter chain automatically. So, all we have to do, if we want to add more filters, is to just declare them as @Bean configurations. For example, for a more advanced filter configuration, if we want a particular filter to apply only to specific URL patterns, we can create a @Bean configuration of a FilterRegistrationBean type and use it to configure the precise settings.
- Python數據挖掘:入門、進階與實用案例分析
- 輕松學大數據挖掘:算法、場景與數據產品
- Hadoop大數據實戰權威指南(第2版)
- 網站數據庫技術
- 大數據技術入門
- gnuplot Cookbook
- TextMate How-to
- 新手學會計(2013-2014實戰升級版)
- Mastering LOB Development for Silverlight 5:A Case Study in Action
- 區塊鏈技術應用與實踐案例
- 從實踐中學習sqlmap數據庫注入測試
- 中文版Access 2007實例與操作
- MySQL數據庫應用與管理
- AndEngine for Android Game Development Cookbook
- Rust High Performance