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