2.3 springboot整合listener

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_16855077/article/details/84875903

1.编写listener

package com.cloudtech.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class HelloListener implements ServletContextListener{

	public void contextInitialized(ServletContextEvent sce) {
		System.out.println("Listener init..............");
	}

	public void contextDestroyed(ServletContextEvent sce) {
		
	}

}

2.编写启动类

package com.cloudtech;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;

/**
 * springboot启动类
* @ClassName: App  
* @Description:   
* @author wude  
* @date 2018年12月6日  
*
 */
@SpringBootApplication
@ServletComponentScan  //在spring boot启动时,会扫描@webServlet,并将该类实例化
public class App2 {
	public static void main(String[] args) {
		SpringApplication.run(App2.class, args);
	}
}

3.启动项目,观察控制台

猜你喜欢

转载自blog.csdn.net/qq_16855077/article/details/84875903
2.3