1、概述

    1.1、当使用  内嵌的Servlet容器(Tomcat、Jetty等)时,将Servlet,Filter,Listener  注册到Servlet容器的方法:

        1.1.1、直接注册Bean            

        1.1.2、注册ServletRegistrationBean、FilterRegistrationBean、ServletListenerRegistrationBean 的Bean 

          eg:

package com.an;

import com.an.servletfilterlistener.MyFilter;
import com.an.servletfilterlistener.MyListener;
import com.an.servletfilterlistener.MyServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean; /**
* @description:
* @author: anpeiyong
* @date: Created in 2019/11/14 19:56
* @since:
*/
@SpringBootApplication
public class MyDemoApplication { public static void main(String[] args) {
SpringApplication.run(MyDemoApplication.class, args);
} /**
* 内嵌Servlet容器中注册Servlet、Filter、Listener---第一种方式:直接注册Bean
*/
@Bean
public MyServlet getMyServlet(){
return new MyServlet();
} @Bean
public MyFilter getMyFilter(){
return new MyFilter();
} @Bean
public MyListener getMyListener(){
return new MyListener();
} /**
* 内嵌Servlet容器中注册Servlet、Filter、Listener---第二种方式:注册ServletRegistrationBean、FilterRegistrationBean、ServletListenerRegistrationBean 的Bean
*/
public ServletRegistrationBean getServletRegistrationBean(){
return new ServletRegistrationBean(new MyServlet(),"/**");
} public FilterRegistrationBean getFilterRegistrationBean(){
FilterRegistrationBean filterRegistrationBean=new FilterRegistrationBean();
filterRegistrationBean.setFilter(new MyFilter());
filterRegistrationBean.setOrder(2);
return filterRegistrationBean;
} public ServletListenerRegistrationBean getServletListenerRegistrationBean(){
return new ServletListenerRegistrationBean(new MyListener());
} }

  

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

  1. SpringBoot注册Servlet/Filter/Listener

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

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

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

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

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

  4. ServletContextInitializer添加 servlet filter listener

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

  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. "C++ Primer Plus" is WAY FUCKING BETTER than "C++ Primer" (For Beginners)!!!

    再看到给初学C++的人推荐C++ Primer的我就要揍人了,真的! 被他妈这帮装逼犯给误导了,耽误了无数的功夫! 就是听这帮傻逼的谣言,说C++ Primer讲解更深入什么的,初学也应该啃这本书,老 ...

  2. [CSP-S模拟测试]:Divisors(数学)

    题目描述 给定$m$个不同的正整数$a_1,a_2,...,a_m$,请对$0$到$m$每一个$k$计算,在区间$[1,n]$里有多少正整数是$a$中恰好$k$个数的约数. 输入格式 第一行包含两个正 ...

  3. TODO 思维模型 尺子 游标卡尺

    100个人 两个思维切入点 1>做对的题怎么分配 m(x)表示答对x道题的最多人数f(x)表示答对x道题的人数 m(0)=5m(1)=20=>f(0)=0m(2)=m(1)+1=21=&g ...

  4. Delphi保存网页中的图片

    WEBBrowser已经打开了URL     V     =   WEBBrowser.Document.body.createControlRange();     V1   =   WEBBrow ...

  5. 屏幕适配dip

    android适配一般使用dpi 那dpi与分辨率,屏幕尺寸的关系 DPI值计算是屏幕对角线的像素值除以屏幕的大小 dip=/ 屏幕尺寸, 比如:计算WVGA(800*480)分辨率,3.7英寸的密度 ...

  6. TCP 为什么是三次握手,而不是两次或四次?

    记得第一次看TCP握手连接的时候,有同样的疑问,我的疑问是,为何不是两次呢?后来随着对网络的理解深入,明白TCP报文是交由IP网络来负责运输,IP网络并不能保证TCP报文到达目的地,既然IP网络是指望 ...

  7. 【FICO系列】SAP FICO模块-财务账期的打开和关闭

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[FICO系列]SAP FICO模块-财务账期的 ...

  8. Windows下通过GitHub+Hexo搭建个人博客的步骤

    Windows下通过GitHub+Hexo搭建个人博客的步骤  https://blog.csdn.net/namechenfl/article/details/90442312 https://bl ...

  9. jmeter处理接口加密和解密

    https://www.liangzl.com/get-article-detail-39672.html https://www.cnblogs.com/artoftest/p/7277996.ht ...

  10. css中word-break、word-wrap和white-space的区别

    css中word-break.word-wrap和white-space的区别 :https://baijiahao.baidu.com/s?id=1578623236521030997&wf ...