zoukankan      html  css  js  c++  java
  • Springboot整合Lintener

    1,方式一

      【1】通过注解扫描完成Listener组件注册

    @WebListener
    public class FirstListener implements ServletContextListener {
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            System.out.println("Lintener...");
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent sce) {
    
        }
    }

      【2】修改启动类

    @SpringBootApplication
    @ServletComponentScan//在Spring Boot启动时会扫描@WebLintener注解,并将该类实例
    public class SpringbootwebApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(SpringbootwebApplication.class, args);
        }
    
    }

    2,方式二

      【1】通过方法完成Listener组件注册

    public class SecondListener implements ServletContextListener {
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            System.out.println("SecondLintener...");
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent sce) {
    
        }
    }

      【2】创建Listener配置类

    @Configuration
    public class ListenerConfig {
        @Bean
        public ServletListenerRegistrationBean getServletListenerRegistrationBean()
        {
            ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean(new SecondListener());
            return bean;
        };
    }
  • 相关阅读:
    UVA 10608 Friends
    UVA 10806 Dijkstra, Dijkstra.
    HDU 3715 Go Deeper
    poj1315
    poj1383
    poj1650
    poj1265
    poj1523
    RedHat9.0虚拟机安装
    注册DirectShow filter时应该注意中文路径
  • 原文地址:https://www.cnblogs.com/yz-bky/p/12690964.html