标签:listen 自动 zed path ring cti ace creat style
package com.aojie.web.listener;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
/**
* @author aojie
* @fuction
* @create 2020-05-03 20:07
*/
@WebListener
public class ContextLoaderListener implements ServletContextListener {
/**
* 服务器启动后自动调用
* @param servletContextEvent
*/
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
//加载资源文件
//1.获取ServletContext对象
ServletContext servletContext = servletContextEvent.getServletContext();
//2.加载资源文件
String contextConfigLocation = servletContext.getInitParameter("contextConfigLocation");
//获取真实路径
String realPath = servletContext.getRealPath(contextConfigLocation);
//加载进内存
try {
FileInputStream fileInputStream = new FileInputStream(realPath);
System.out.println(fileInputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println("ServletContext对象被创建了");
}
/**
* 服务器正常关闭后该方法调用
* @param servletContextEvent
*/
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
System.out.println("ServletContext对象被销毁了");
}
}
标签:listen 自动 zed path ring cti ace creat style
原文地址:https://www.cnblogs.com/aojie/p/12823544.html