java alan liu_springboot 整合 listener

1:查看效果

a7837b2d9bafaca8fc0335fc7c708635.png

aef05bb588906bc71f4777ea656945e8.png

1:FirstListenerpackage com.AlanCode.springBoot.Listener;

/**

* @author Alan_liu

* @Create 2021/2/16 10:58

*/

import javax.servlet.ServletContextEvent;

import javax.servlet.ServletContextListener;

import javax.servlet.annotation.WebListener;

/**

*@program: SpringBootAddListtener

*@description: springboot 整合 listener 方式一:

*

*

* *传统spring 方式配置 listener 内容:

* *

* * com.alancode.springboot.listener.FirstListener

* *

*

*@author: Alan_Liu

*@create: 2021-02-16 10:58

*/

@WebListener

public class FirstListener implements ServletContextListener {

@Override

public void contextInitialized(ServletContextEvent sce) {

System.out.println("--------------listener.......init.....---------------------------------------");

}

@Override

public void contextDestroyed(ServletContextEvent sce){

}

}

2:ListenerApplicationpackage com.AlanCode.springBoot;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.web.servlet.ServletComponentScan;

/**

* springboot 整合 listener 方式一

* @author Alan_Liu

*/

@SpringBootApplication

@ServletComponentScan

public class ListenerApplication {

public static void main(String[] args) {

SpringApplication.run(ListenerApplication.class, args);

}

}

/***

*

*

**注意:

**关于编写启动器需要注意的问题。

**启动器存放位置:启动器可以和controller 位于同一个包 package下,或者位于controller的上一级包。

**但是不能把该文件放到controller平行级的包或者其子包下。

* ServletComponentScan 含义:

* 在springboot 启动时候进行扫描@webServlet注解的所有servlet、filter类。并将该类实例化

*

* ***/

3: pom.xml<?xml version="1.0" encoding="UTF-8"?>

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

org.springframework.boot

spring-boot-starter-parent

2.4.2

com.AlanCode.springBoot

springBootAddListener

0.0.1-SNAPSHOT

springBootAddListener

Demo project for Spring Boot

1.8

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-maven-plugin

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值