SpringBoot之Servlet、Filter、Listener配置
在SpringBoot中是不需要配置web.xml的,那么原来在web.xml中配置的Servlet、Filter、Listener现在怎么弄呢?
SpringBoot提供了三种Bean FilterRegistrationBean、ServletRegistrationBean、ServletListenerRegistrationBean
分别对应配置原生的Filter、Servlet、Listener。
@Bean
public ServletRegistrationBean indexServletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new IndexServlet());
registration.addUrlMappings("/hello");
return registration;
} @Bean
public FilterRegistrationBean indexFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean(new IndexFilter());
registration.addUrlPatterns("/");
return registration;
}
@Bean
public ServletListenerRegistrationBean servletListenerRegistrationBean(){
ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();
servletListenerRegistrationBean.setListener(new IndexListener());
return servletListenerRegistrationBean;
}
SpringBoot之Servlet、Filter、Listener配置的更多相关文章
- SpringBoot注册Servlet/Filter/Listener
由于SpringBoot默认是以jar包的方式启动嵌入式的Servlet容器来启动SpringBoot的web应用,那么没有web.xml文件,如何配置我们的三大Web基础组件呢? 通过使用XXXRe ...
- springboot 注入Servlet,Filter,Listener的方法
其实就是注入 FilterRegistrationBean . ServletRegistrationBean . ServletListenerRegistrationBean 这三个类 直接上 ...
- SpringBoot学习笔记(6)----SpringBoot中使用Servlet,Filter,Listener的三种方式
在一般的运用开发中Controller已经大部分都能够实现了,但是也不排除需要自己实现Servlet,Filter,Listener的方式,SpringBoot提供了三种实现方式. 1. 使用Bean ...
- ServletContextInitializer添加 servlet filter listener
ServletContextInitializer添加 servlet filter listener https://www.cnblogs.com/pomer-huang/p/9639322.ht ...
- servlet filter listener interceptor 知识点
这篇文章主要介绍 servlet filter listener interceptor 之 知识点.博文主要从 概念,生命周期,使命介绍其区别.详情如下: 概念 生命周期 使命 servlet ...
- JavaWeb三大组件(Servlet,Filter,Listener 自己整理,初学者可以借鉴一下)
JavaWeb三大组件(Servlet,Filter,Listener 自己整理,初学者可以借鉴一下) Reference
- SpringBoot---注册Servlet,Filter,Listener
1.概述 1.1.当使用 内嵌的Servlet容器(Tomcat.Jetty等)时,将Servlet,Filter,Listener 注册到Servlet容器的方法: 1.1.1.直接注册Bean ...
- SpringBoot整合WEB开发--(九)整合Servlet,Filter,Listener
简介: 如果需要整合第三方框架时,可能还是不得不使用Servlet,Filter,Listener,Springboot中也有提供支持. @WebServlet("/my") pu ...
- servlet/filter/listener/interceptor区别与联系
转自:http://www.cnblogs.com/doit8791/p/4209442.html servlet.filter.listener是配置到web.xml中(web.xml 的加载顺序是 ...
- 【转】servlet/filter/listener/interceptor区别与联系
原文:https://www.cnblogs.com/doit8791/p/4209442.html 一.概念: 1.servlet:servlet是一种运行服务器端的java应用程序,具有独立于平台 ...
随机推荐
- 关于CoInitialize和CoUninitialize调用的有关问题
本人封装了一个类,里面需要用到ADO连接数据库, 所以需要初始化COM环境以及释放COM环境, 我打算在构造函数里面执行CoInitialize,在析构函数里面执行CoUninitialize 但是程 ...
- Duilib教程-简单介绍
在读这篇博客的时候,可能您已经对duilib有一定的了解.所以,我并不打算对duilib进行过多的介绍.它的内核首先由外国人编写,后来由国人一个小组接过来继续编写,于是就有了现在的Duilib. 1. ...
- Android开发:《Gradle Recipes for Android》阅读笔记(翻译)6.1——推荐配置
问题: 你想要提高Gradle的构建效率. 解决方案: 使用下面推荐的技术组合. 讨论: 首先,这里没有可以影响app表现的建议.有很多你可以做的事来提高app,很多都和Android的混淆工具有关. ...
- std::stringstream(2)
stringstream本身的复制构造函数是私有的,无法直接用,于是带来了一些复杂的问题 网上,流传着几种办法,如streamA.str(streamB.str()),但这种办法,复制的仅仅是初始化时 ...
- [MongoDB]学习笔记--User管理
1. 创建一个超级用户 use admin db.createUser( { user: "adminUserName", pwd: "userPassword" ...
- CF679C(Bear and Square Grid) 经典好题
题目链接:传送门 题目大意:给你一个n*n包含".","X"的图,你有一次机会选择一个k*k的子矩阵,将子矩阵全部变为".",问当操作过后, ...
- java jdk 1.6 下载
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-41940 ...
- mfc中 控件 对话框 添加颜色 背景图片
1 设置对话框透明 在设置控件颜色中要使用 nCtlColor Contains one of the following values, specifying the type of control ...
- ES正在弱化type这个概念
百度Elasticsearch-产品描述-介绍-百度云 https://cloud.baidu.com/doc/BES/System.html#.E5.9F.BA.E6.9C.AC.E6.A6.82. ...
- (转) RabbitMQ学习之延时队列
http://blog.csdn.net/zhu_tianwei/article/details/53563311 在实际的业务中我们会遇见生产者产生的消息,不立即消费,而是延时一段时间在消费.Rab ...