springboot使用过滤器Filter
先创建过滤器配置类:
## 引入的包部分省略...
@Configuration
public class FilterConfig {
@SuppressWarnings({"rawtypes", "unchecked"})
@Bean
public FilterRegistrationBean registFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(this.SzlDemoFiler());
registration.addUrlPatterns("/demo/*");
registration.setName("JimmyShan");
registration.setOrder(1);
return registration;
} @Bean
public Filter SzlDemoFilter() {
return new SzlDemoFilter();
} }
然后,我们自定义类实现Filter接口:
## 引入的包部分省略...
public class SzlDemoFilter implements Filter {
private final static Logger log = LoggerFactory.getLogger(SzlDemoFilter.class);
//@Autowired
//private DemoService demoService;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
long start = System.currentTimeMillis();
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
String methodName = req.getMethod();
log.info("Request method is : " + methodName);
String uri = req.getRequestURI();
log.info("Request uri is : " + uri);
chain.doFilter(request, response);
log.info("Execute filter = " + (System.currentTimeMillis() - start) + " ms");
}
}
springboot使用过滤器Filter的更多相关文章
- Springboot自定义过滤器Filter
前言:自己写了个Springboot项目,最近写的功能越来越多,结合业务已经要写过滤器Filter来过滤处理一些请求. 在网上看了几篇博客,总结如下: 过滤器配置方式有两种: 1.通过@WebFilt ...
- SpringBoot 利用过滤器Filter修改请求url地址
要求: 代码中配置的url路径为http://127.0.0.1/api/associates/queryAssociatesInfo 现在要求http://127.0.0.1/associates/ ...
- SpringBoot系列教程web篇之过滤器Filter使用指南扩展篇
前面一篇博文介绍了在 SpringBoot 中使用 Filter 的两种使用方式,这里介绍另外一种直接将 Filter 当做 Spring 的 Bean 来使用的方式,并且在这种使用方式下,Filte ...
- SpringBoot系列教程web篇之过滤器Filter使用指南
web三大组件之一Filter,可以说是很多小伙伴学习java web时最早接触的知识点了,然而学得早不代表就用得多.基本上,如果不是让你从0到1写一个web应用(或者说即便从0到1写一个web应用) ...
- springboot(五)过滤器和拦截器
前言 过滤器和拦截器二者都是AOP编程思想的提现,都能实现诸如权限检查.日志记录等.二者有一定的相似之处,不同的地方在于: Filter是servlet规范,只能用在Web程序中,而拦截器是Sprin ...
- SpringBoot学习(八)-->SpringBoot之过滤器、监听器
本文将直接使用@WebFilter和@WebListener的方式,完成一个Filter 和一个 Listener. 过滤器(Filter)和 监听器(Listener)的注册方法和 Servlet ...
- SpringBoot2.x过滤器Filter和使用Servlet3.0配置自定义Filter实战
补充:SpringBoot启动日志 1.深入SpringBoot2.x过滤器Filter和使用Servlet3.0配置自定义Filter实战(核心知识) 简介:讲解SpringBoot里面Filter ...
- springboot 增加过滤器方法
在访问服务器时,我们需要控制用户是否允许权限,这个时候可以使用过滤器. 在springboot 配置过滤器的方法如下: 编写过滤器代码: package com.neo.filter; import ...
- springboot jsp,过滤器,拦截器
springboot使用jsp,过滤器,拦截器(拦截器与过滤器区别重点) jsp使用配置 一 创建springboot项目在maven中暂时只添加两个Dependencies :devtools(热部 ...
随机推荐
- h5开发安卓机型点击输入框调起输入法,输入框被键盘遮挡的解决方法
前言: 从以前的项目中找一个问题的解决方案,顺带找到了这个安卓机型调起输入法,页面没有自动上滑导致输入框被弹起的键盘遮挡的解决方案.这个问题只有安卓机型页面中的输入框处于底部(也就是底部键盘区域)的时 ...
- python路径相关技巧
在文件C:\work\python\rqalpha\rqalpha\utils\config.py 找文件:C:\work\python\rqalpha\rqalpha\config.yml 则通过下 ...
- 【环境搭建与软件安装】How to install CUDNN or uninstall
前言 CuDnn是用于深度学习的GPU加速库,安装好NVIDIA和CUDA之后,安装CuDnn就简单多了,可参考官方文档. 操作过程 1. 下载cuDnn. 需要在NVIDIA官网注册账号,登录之后下 ...
- [LeetCode] 82. Remove Duplicates from Sorted List II 移除有序链表中的重复项 II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [LeetCode] 106. Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- [LeetCode] 388. Longest Absolute File Path 最长的绝对文件路径
Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...
- [LeetCode] 624. Maximum Distance in Arrays 数组中的最大距离
Given m arrays, and each array is sorted in ascending order. Now you can pick up two integers from t ...
- PCL读取PCD文件的数据
1.pcd文件——rabbit.pcd 链接:https://pan.baidu.com/s/1v6mjPjwd7fIqUSjlIGTIGQ提取码:zspx 新建项目pcl rabbit.pcd 和p ...
- webpack打包完成,复制,打包,移动,删除已生成的文件插件
const FileManagerPlugin = require('filemanager-webpack-plugin'); 详情请到 https://www.npmjs.com/ 一看究竟 贴个 ...
- 使用Xshell采用证书登录Linux
1,工具--- 用户key生成向导,选择秘钥类型,注意DSA只能选择1024位级以下,超过1024位的服务器不认. 2 给公钥取一个名字,并设置密码,保存为文件 3 在linux 用户目录,用cd ...