懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
提交 | 用户 | 时间
71e81e 1 /**
2  * Copyright 2018-2020 stylefeng & fengshuonan (sn93@qq.com)
3  * <p>
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * <p>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p>
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package cn.stylefeng.guns.sys.core.listener;
17
18 import javax.servlet.ServletContext;
19 import javax.servlet.ServletContextEvent;
20 import javax.servlet.ServletContextListener;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 /**
25  * ServletContext监听器
26  *
27  * @author stylefeng
28  * @Date 2018/2/22 21:07
29  */
30 public class ConfigListener implements ServletContextListener {
31
32     private static Map<String, String> conf = new HashMap<>();
33
34     public static Map<String, String> getConf() {
35         return conf;
36     }
37
38     @Override
39     public void contextDestroyed(ServletContextEvent arg0) {
40         conf.clear();
41     }
42
43     @Override
44     public void contextInitialized(ServletContextEvent evt) {
45         ServletContext sc = evt.getServletContext();
46
47         //项目发布,当前运行环境的绝对路径
48         conf.put("realPath", sc.getRealPath("/").replaceFirst("/", ""));
49
50         //servletContextPath,默认""
51         conf.put("contextPath", sc.getContextPath());
52     }
53
54 }