Spring boot 注册Filter , Listener, Servlet
1: ServletRegistrationBean Servlet
@Bean
public ServletRegistrationBean myServlet(){
ServletRegistrationBean registrationBean = new ServletRegistrationBean(new MyServlet(),"/myServlet");
return registrationBean;
}
或者通过@WebServlet注解也可以.
2:FilterRegistrationBean 过滤器
@Bean
public FilterRegistrationBean myFilter(){
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(new MyFilter());
//过滤的请求路径
registrationBean.setUrlPatterns(Arrays.asList("/hello","/myServlet"));
return registrationBean;
}
public class MyFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("MyFilter process...");
chain.doFilter(request,response);
}
@Override
public void destroy() {
}
}
3:ServletListenerRegistrationBean 监听器
@Bean
public ServletListenerRegistrationBean myListener(){
ServletListenerRegistrationBean<MyListener> registrationBean = new ServletListenerRegistrationBean<>(new MyListener());
return registrationBean;
}
myListener 实现 ServletContextListener即可
Spring boot 注册Filter , Listener, Servlet的更多相关文章
- Spring Boot 注册 Servlet 的三种方法,真是太有用了!
本文栈长教你如何在 Spring Boot 注册 Servlet.Filter.Listener. 你所需具备的基础 什么是 Spring Boot? Spring Boot 核心配置文件详解 Spr ...
- Spring Boot → 08:嵌入式Servlet容器自定义
Spring Boot → 08:嵌入式Servlet容器自定义
- SpringBoot 源码解析 (七)----- Spring Boot的核心能力 - 自定义Servlet、Filter、Listener是如何注册到Tomcat容器中的?(SpringBoot实现SpringMvc的原理)
上一篇我们讲了SpringBoot中Tomcat的启动过程,本篇我们接着讲在SpringBoot中如何向Tomcat中添加Servlet.Filter.Listener 自定义Servlet.Filt ...
- [Spring Boot] 使用多个Servlet
当使用Spring boot的嵌入式servlet容器时,可以通过Spring bean或扫描Servlet组件的方式注册Servlet.Filter和Servlet规范的所有监听器(例如HttpSe ...
- Spring Boot配置Filter
此博客是学习Spring Boot过程中记录的,一来为了加深自己的理解,二来也希望这篇博客能帮到有需要的朋友.同时如果有错误,希望各位不吝指教 一.通过注入Bean的方式配置Filter: 注意:此方 ...
- Javaweb里面的filter,listener,servlet
Filter 1Filter是什么:是过滤器简称 2Filter有什么作用:在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装 ...
- spring boot 与 filter
spring boot 里面用拦截器好像比用过滤器多一些. 在过滤器中, 并不能获取到action的相关信息, 会造成很多的麻烦和功能欠缺. 那, 这里就用过滤器做一个小栗子, 实际使用过程中, 不会 ...
- Spring Boot实践——Filter实现
Filter介绍 Filter是Servlet规范规定的,不属于spring框架,也是用于请求的拦截.但是它适合更粗粒度的拦截,在请求前后做一些编解码处理.日志记录等. 一个Filter包括:1).在 ...
- Spring Boot使用监听器Listener
之前介绍了在Spring Boot中使用过滤器:https://www.cnblogs.com/zifeiy/p/9911056.html 接下来介绍使用监听器Listener. 下面是一个例子: p ...
随机推荐
- 科学-建筑学-事务所:KPF
ylbtech-科学-建筑学-事务所:KPF 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 0. https://www.kpf.com/projects/na ...
- Linux创建桥接网络
图形化创建 #nm-connection-editor & 选择桥接 设置桥接网络 点击添加 模式选择以太网 添加上行网卡 # brctl show 删除桥接 # nmcli connecti ...
- win下使用git-bash工具进行ssh免密登录服务器
1.ssh-keygen.exe 生成公钥私钥(.pub) 2.ssh-agent.exe bash 指定工具 3.ssh-add.exe **** 添加私钥 OK
- go语言功能代码
一.数据类型转换 package main import ( "fmt" "strconv" ) func main() { //int到string str ...
- linux下新建(touch)\复制(cp)\剪切(mv)\删除(rm)文件
touch :新建多个文件,中间用空格隔开 touch file1 file2 cp: mv:剪切 rm:删除文件
- ZooKeeper系列(6):ZooKeeper机制架构
一.ZooKeeper权限管理机制 1.1 权限管理ACL(Access Control List) ZooKeeper 的权限管理亦即ACL 控制功能,使用ACL来对Znode进行访问控制.ACL的 ...
- MapReduce Demo
功能:统计公司员工一个月内手机上网上行流量.下行流量及总流量. 测试数据如下: 13612345678 6000 1000 13612345678 2000 3000 13 ...
- vue 要点
一: 1. 如果在实例创建之后添加新的属性到实例上,它不会触发视图更新. 2. v-show 的元素会始终渲染并保持在 DOM 中.v-show 是简单的切换元素的 CSS 属性 display.
- cobbler部署centos6与centos7系列
cobbler部署centos6与centos7系列 转载自:http://www.jianshu.com/p/a4bed77bf40d 版权声明:完全抄自 http://www.jianshu.co ...
- jmeter造当前时间,未来时间,历史时间
需求: 需要测试POST接口参数中的time,且需要造时间戳 1.当前系统时间获取 函数:__time 应用: ${__time(yyyy-MM-dd HH:mm:ss,)} ${__time(yyy ...