- 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.
- 計算機組成原理與接口技術:基于MIPS架構實驗教程(第2版)
- Java Data Science Cookbook
- Mastering Machine Learning with R(Second Edition)
- Spark大數據分析實戰
- 重復數據刪除技術:面向大數據管理的縮減技術
- 計算機組裝與維護(微課版)
- Access 2010數據庫程序設計實踐教程
- 算法設計與分析
- 數據挖掘與機器學習-WEKA應用技術與實踐(第二版)
- 標簽類目體系:面向業務的數據資產設計方法論
- Oracle 11g數據庫管理與開發基礎教程
- ORACLE 11g權威指南
- SQL Server 2012數據庫技術及應用(第4版)
- 工業大數據分析實踐
- Discovering Business Intelligence Using MicroStrategy 9