SpringBoot监听类——小结②

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;
    }
}

 

posted @ 2023-03-07 20:48  叁三彡  阅读(21)  评论(0编辑  收藏  举报