首页 > 其他分享 >SpringBoot监听类——小结②

SpringBoot监听类——小结②

时间:2023-03-07 20:55:53浏览次数:25  
标签:ServletListenerRegistrationBean SpringBoot springframework org import 小结 监听

SpringBoot的监听类的配置有两种方法,一是通过SpringBoot的自动扫描功能来进行,但是前提是在Listener类上添加相应的注解

@WebListener

 

二是自己进行相应的配置类编写

package com.example.springbootdemo4;

import com.example.springbootdemo4.listener.SecondListener;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class ListenerConfig {
    @Bean
    public ServletListenerRegistrationBean getServletListenerRegistrationBean () {
        ServletListenerRegistrationBean  bean =
                new ServletListenerRegistrationBean(new SecondListener());
        return bean;
    }
}

 

标签:ServletListenerRegistrationBean,SpringBoot,springframework,org,import,小结,监听
From: https://www.cnblogs.com/hsq-sansansan/p/17189627.html

相关文章

  • Spring Boot | 事件监听器异步处理事件,实现代码解耦
    一、简介SpringBoot事件监听器(EventListener)用于在应用程序的生命周期中,监听SpringBoot应用程序中各种事件的发生,以便在事件发生时执行某些特定的操作。二、集成步骤1......
  • SpringBoot
    1.自动配置父项目<parent>  <groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.3.4</ver......
  • SpringBoot Cglib代理不生效
    启动项目抛出异常:Causedby:org.springframework.beans.factory.BeanNotOfRequiredTypeException:Beannamed'testTableDao'isexpectedtobeoftype'com.TestTableD......
  • springboot 2.6版本使用knife4j的坑
    1.yml增加配置application.yml spring: mvc:   pathmatch:     matching-strategy:ANT_PATH_MATCHER  https://blog.csdn.net/weixin_44307818/arti......
  • ElasticSearch 实现分词全文检索 - Java SpringBoot ES 索引操作
    目录ElasticSearch实现分词全文检索-概述ElasticSearch实现分词全文检索-ES、Kibana、IK安装ElasticSearch实现分词全文检索-Restful基本操作ElasticSearch......
  • 每日小结(11)
    今天写了一个小测试,关于数组的子数组之和最大的。今天我学习了一种解决数组问题的算法,即统计数组中子数组之和最大的问题。该算法可以在O(n)的时间复杂度内解决这个问题,因......
  • SpringBoot SSM vue课程作业在线批阅系统
    SpringBootSSMvue课程作业在线批阅系统登录新闻公告在线留言课程管理指定课代表作业下发作业审批评分在线预览使用技术:SpringBoot或SSM +Mybatis+Mysql......
  • SpringBoot(十):thymeleaf + JSR303实现表单验证
    一、Person类packagecom.jms.pojo;importlombok.Data;importjavax.validation.constraints.*;@DatapublicclassPerson{@NotBlank(message="姓名不......
  • SpringBoot中基于拦截器实现登录验证功能
    拦截器简介拦截器是属于springmvc体系的,只能拦截controller的请求。拦截器(Interceptor)是一种动态拦截方法调用的机制,在SpringMVC中动态拦截控制器方法的执行。Interceptor......
  • springboot项目jar包混淆加密
    混淆工具jar包混淆工具挺多的,实现原理不尽相同,这里使用的classfinal加密执行以下命令java-jarclassfinal-fatjar.jar-fileyourproject.jar-libjarsa.jar,b.jar-......