Parcourir la source

second commit

zhangxiaoyu il y a 2 ans
Parent
commit
d66dbe6baa

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

@@ -10,8 +10,11 @@ import javax.servlet.ServletContextListener;
10
 public class ContextLoadListener implements ServletContextListener {
10
 public class ContextLoadListener implements ServletContextListener {
11
     public void contextInitialized(ServletContextEvent sce) {
11
     public void contextInitialized(ServletContextEvent sce) {
12
 //        ServletContextListener.super.contextInitialized(sce);
12
 //        ServletContextListener.super.contextInitialized(sce);
13
-        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
14
         ServletContext servletContext = sce.getServletContext();
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
         servletContext.setAttribute("app",annotationConfigApplicationContext);
18
         servletContext.setAttribute("app",annotationConfigApplicationContext);
16
         System.out.println("servletContextLoader");
19
         System.out.println("servletContextLoader");
17
     }
20
     }

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

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