Kaynağa Gözat

second commit

zhangxiaoyu 2 yıl önce
ebeveyn
işleme
d66dbe6baa

+ 4 - 1
springMvc/src/main/java/com/listener/ContextLoadListener.java

@@ -10,8 +10,11 @@ import javax.servlet.ServletContextListener;
10 10
 public class ContextLoadListener implements ServletContextListener {
11 11
     public void contextInitialized(ServletContextEvent sce) {
12 12
 //        ServletContextListener.super.contextInitialized(sce);
13
-        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
14 13
         ServletContext servletContext = sce.getServletContext();
14
+        // 获取web.xml中默认设置参数
15
+        String initParameter = servletContext.getInitParameter("testName");
16
+        System.out.println(initParameter);
17
+        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
15 18
         servletContext.setAttribute("app",annotationConfigApplicationContext);
16 19
         System.out.println("servletContextLoader");
17 20
     }

+ 4 - 0
springMvc/src/main/webapp/WEB-INF/web.xml

@@ -28,6 +28,10 @@
28 28
   <listener>
29 29
     <listener-class>com.listener.ContextLoadListener</listener-class>
30 30
   </listener>
31
+  <context-param>
32
+    <param-name>testName</param-name>
33
+    <param-value>test1</param-value>
34
+  </context-param>
31 35
 
32 36
   <!-- Servlet Filters ================================================ -->
33 37
   <servlet>