zoukankan      html  css  js  c++  java
  • Springboot-Listener

                                                          springboot-Listener

    package com.bjsxt.listener;
    
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    import javax.servlet.annotation.WebListener;
    /**
     * springBoot整合Listener
     *
     *<listener>
     *    <listener-class>com.bjsxt.listener.FirstListener</listener-class>
     *</listener>
     */
    @WebListener
    public class FirstListener implements ServletContextListener {
    
        @Override
        public void contextDestroyed(ServletContextEvent arg0) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public void contextInitialized(ServletContextEvent arg0) {
            System.out.println("Listener...init......");
    
        }
    
    }
    FirstListener
    package com.bjsxt.listener;
    
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    /**
     * springBoot整合Listener方式二。
     *
     *
     */
    public class SecondListener implements ServletContextListener {
    
        @Override
        public void contextDestroyed(ServletContextEvent arg0) {
            // TODO Auto-generated method stub
        }
    
        @Override
        public void contextInitialized(ServletContextEvent arg0) {
            System.out.println("SecondListener..init.....");
        }
    
    }
    SecondListener
    package com.bjsxt;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.web.servlet.ServletComponentScan;
    
    /**
     * springBoot整合Listener方式一
     *
     *
     */
    @SpringBootApplication
    @ServletComponentScan
    public class App {
    
        public static void main(String[] args) {
            SpringApplication.run(App.class, args);
        }
    
    }
    App
    package com.bjsxt;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
    import org.springframework.context.annotation.Bean;
    
    import com.bjsxt.listener.SecondListener;
    
    /**
     * SpringBoot整合Listener方式二
     *
     *
     */
    @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;
        }
    }
    App2
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
      </parent>
      <groupId>com.bjsxt</groupId>
      <artifactId>04-spring-boot-Listener</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      
      <!-- jdk1.7 -->
      <properties>
          <java.version>1.7</java.version>
      </properties>
      
      <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    </project>
    pom.xml
  • 相关阅读:
    服务端渲染
    node基础
    vue不同组件间的通信
    mui底部导航栏
    在mui中引入自定义的字体图标
    axios的使用
    vue多视图
    多元线性回归:波士顿房价预测问题TesnsorFlow实战
    MNIST手写数字识别:分类应用入门(实践篇)
    7-3 java高级 22_19寻找最大块的问题 (20 分)
  • 原文地址:https://www.cnblogs.com/ou-pc/p/9782063.html
Copyright © 2011-2022 走看看