由于SpringBoot默认是以jar包的方式启动嵌入式的Servlet容器来启动SpringBoot的web应用,那么没有web.xml文件,如何配置我们的三大Web基础组件呢?

通过使用XXXRegistrationBean如何注册Servlet:

 
如何注册Servlet:
@Bean
public ServletRegistrationBean myServlet(){
ServletRegistrationBean registrationBean = new ServletRegistrationBean(new MyServlet(),"/myServlet");
return registrationBean;
}
//Myservlet extends HttpServlet 如何注册Filter:

 @Bean
  public FilterRegistrationBean myFilter(){
  FilterRegistrationBean registrationBean = new FilterRegistrationBean();
  registrationBean.setFilter(new MyFilter());
  registrationBean.setUrlPatterns(Arrays.asList("/hello","/myServlet"));
  return registrationBean;
 }

如何注册Listener:

@Bean
  public ServletListenerRegistrationBean myListener(){
  ServletListenerRegistrationBean<MyListener> registrationBean = new
  ServletListenerRegistrationBean<>(new MyListener());
  return registrationBean;
·}

//MyListener implements ServletContextListener等6大接口

SpringBoot注册Servlet/Filter/Listener的更多相关文章

  1. springboot 注入Servlet,Filter,Listener的方法

    其实就是注入 FilterRegistrationBean . ServletRegistrationBean . ServletListenerRegistrationBean 这三个类   直接上 ...

  2. SpringBoot学习笔记(6)----SpringBoot中使用Servlet,Filter,Listener的三种方式

    在一般的运用开发中Controller已经大部分都能够实现了,但是也不排除需要自己实现Servlet,Filter,Listener的方式,SpringBoot提供了三种实现方式. 1. 使用Bean ...

  3. ServletContextInitializer添加 servlet filter listener

    ServletContextInitializer添加 servlet filter listener https://www.cnblogs.com/pomer-huang/p/9639322.ht ...

  4. SpringBoot---注册Servlet,Filter,Listener

    1.概述 1.1.当使用  内嵌的Servlet容器(Tomcat.Jetty等)时,将Servlet,Filter,Listener  注册到Servlet容器的方法: 1.1.1.直接注册Bean ...

  5. JavaWeb三大组件(Servlet,Filter,Listener 自己整理,初学者可以借鉴一下)

    JavaWeb三大组件(Servlet,Filter,Listener 自己整理,初学者可以借鉴一下) Reference

  6. servlet filter listener interceptor 知识点

    这篇文章主要介绍 servlet filter listener interceptor 之 知识点.博文主要从 概念,生命周期,使命介绍其区别.详情如下:   概念 生命周期 使命 servlet ...

  7. SpringBoot注册Servlet、Filter、Listener

    SpringBoot默认是以jar包的方式启动嵌入式的Servlet容易来启动SpringBoot的Web应用,没有web.xml文件 因此我们可以使用以下方式来注册Servlet.Filter.Li ...

  8. SpringBoot整合WEB开发--(九)整合Servlet,Filter,Listener

    简介: 如果需要整合第三方框架时,可能还是不得不使用Servlet,Filter,Listener,Springboot中也有提供支持. @WebServlet("/my") pu ...

  9. Spring Boot整合Servlet,Filter,Listener,访问静态资源

    目录 Spring Boot整合Servlet(两种方式) 第一种方式(通过注解扫描方式完成Servlet组件的注册): 第二种方式(通过方法完成Servlet组件的注册) Springboot整合F ...

随机推荐

  1. JMeter学习(十四)JMeter函数学习(转载)

    转载自 http://www.cnblogs.com/yangxia-test JMeter函数是一些能够转化在测试树中取样器或者其他配置元件的域的特殊值.一个函数的调用就像这样:${_functio ...

  2. java集合: ArrayList源码浅析

    ArrayList 是一个动态数组,线程不安全 ,允许元素为null. ArrayList的数据结构是数组,查询比较方便. ArrayList类的接口 public class ArrayList&l ...

  3. java面试题:网络通信

    网络分层 Q:OSI网络七层模型. Http Q:http协议的状态码有哪些?含义是什么? 200,服务器已成功处理了请求. 302,重定向. 400,错误请求. 401,未授权,请求要求身份验证. ...

  4. 第十一章 串 (a)ADT

  5. java 空格替换%20

    public String replaceSpace(StringBuffer str2) { StringBuffer str4 = new StringBuffer(); int length=s ...

  6. width多少,超过了用....表示

    maxWidth:'140px',whiteSpace:'nowrap',overflow:'hidden',textOverflow:'ellipsis'

  7. [leetcode]694. Number of Distinct Islands你究竟有几个异小岛?

    Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...

  8. 定时器NSTimer

    /** 添加定时器 */@property (nonatomic, strong) NSTimer *timer; - (void)addTimer{ // 2秒后,自己 调用nextImage方法 ...

  9. 安装git工具在ubuntu系统

    Git is one of the most popular tools used for distributed version control system(VCS). Git is common ...

  10. (转载)Ubuntu下安装Qt

    转载自:http://blog.csdn.net/timidsmile/article/details/7716201 Ubuntu下安装Qt 1: sudo apt-get install qt4- ...