官术网_书友最值得收藏!

Configuring custom servlet filters

In a real-world web application, we almost always find a need to add facades or wrappers to service requests, to log them, filter out bad characters for XSS, perform authentication, and so on. Out of the box, Spring Boot automatically adds OrderedCharacterEncodingFilter and HiddenHttpMethodFilter, but we can always add more. Let's see how Spring Boot helps us achieve this task.

Among the various assortments of Spring Boot, Spring Web, Spring MVC, and others, there is already a vast variety of different servlet filters that are available and all we have to do is define them as beans in the configuration. Let's say that our application will be running behind a load balancer proxy and we would like to translate the real request IP that is used by the users instead of the IP from the proxy when our application instance receives the request. Luckily, Apache Tomcat 8 already provides us with an implementation: RemoteIpFilter. All we will need to do is add it to our filter chain.

主站蜘蛛池模板: 金塔县| 洮南市| 五台县| 尉氏县| 疏勒县| 华坪县| 三亚市| 崇文区| 宜宾县| 清水河县| 天水市| 中牟县| 兴义市| 安化县| 元氏县| 鸡西市| 黄龙县| 竹山县| 嘉峪关市| 长寿区| 苗栗市| 庄河市| 舟山市| 阳信县| 荔浦县| 贡觉县| 桃园县| 中宁县| 疏附县| 金阳县| 大足县| 汉阴县| 成安县| 西藏| 阜康市| 内乡县| 杭州市| 呼伦贝尔市| 四会市| 阳信县| 高阳县|