zoukankan      html  css  js  c++  java
  • 02-03:springboot 整合listener

    1.通过注解扫描完成Listener组件的注册

    1.1 编写listener

    /**
     * Springboot 整合listener
     */
    import javax.servlet.ServletContextListener;
    import javax.servlet.annotation.WebListener;
    @WebListener
    public class FirstListener implements ServletContextListener {
    
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            // TODO Auto-generated method stub
            System.out.println("listener Init");
        }
        @Override
        public void contextDestroyed(ServletContextEvent sce) {
            // TODO Auto-generated method stub
        }
    }

    1.2编写启动类

    /**
     * springboot整合listener 方式一
     * @author Administrator
     *
     */
    @SpringBootApplication
    @ServletComponentScan
    public class App {
        public static void main(String[] args) {
            SpringApplication.run(App.class, args);
        }
    }

    2.通过方法完成Listener组件的注册

    2.1编写listener

    public class SecondListener implements ServletContextListener {
    
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            // TODO Auto-generated method stub
            System.out.println("secondListener....");
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent sce) {
            // TODO Auto-generated method stub
    
        }
    
    }

    2.2 编写启动器

    /**
     * SpringBoot 整合Listener方式2
     * 
     * @author Administrator
     *
     */
    @SpringBootApplication
    public class App2 {
        public static void main(String[] args) {
            SpringApplication.run(App2.class, args);
        }
        /**
         * 注册listener
         */
        @Bean
        public ServletListenerRegistrationBean<SecondListener> getServletListenerRegistrationBean(){
            ServletListenerRegistrationBean<SecondListener> bean= new ServletListenerRegistrationBean<SecondListener>(new SecondListener());
            return bean;
        }
    }
  • 相关阅读:
    SCILAB简介[z]
    UG OPEN API编程基础 2约定及编程初步
    Office 2003与Office 2010不能共存的解决方案
    UG OPEN API 编程基础 3用户界面接口
    NewtonRaphson method
    UG OPEN API编程基础 13MenuScript应用
    UG OPEN API编程基础 14API、UIStyler及MenuScript联合开发
    UG OPEN API编程基础 4部件文件的相关操作
    UG OPEN API编程基础 1概述
    16 UG Open的MFC应用
  • 原文地址:https://www.cnblogs.com/wangjianly/p/9794324.html
Copyright © 2011-2022 走看看