|
@@ -1,25 +1,26 @@
|
1
|
1
|
package com.listener;
|
2
|
2
|
|
3
|
3
|
import com.config.SpringConfig;
|
|
4
|
+import org.springframework.context.ApplicationContext;
|
4
|
5
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
6
|
+import org.springframework.context.support.ClassPathXmlApplicationContext;
|
5
|
7
|
|
6
|
8
|
import javax.servlet.ServletContext;
|
7
|
9
|
import javax.servlet.ServletContextEvent;
|
8
|
10
|
import javax.servlet.ServletContextListener;
|
9
|
11
|
|
10
|
12
|
public class ContextLoadListener implements ServletContextListener {
|
|
13
|
+ @Override
|
11
|
14
|
public void contextInitialized(ServletContextEvent sce) {
|
12
|
15
|
|
13
|
16
|
ServletContext servletContext = sce.getServletContext();
|
14
|
17
|
|
15
|
|
- String initParameter = servletContext.getInitParameter("testName");
|
16
|
|
- System.out.println(initParameter);
|
17
|
|
- AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
|
18
|
|
- servletContext.setAttribute("app",annotationConfigApplicationContext);
|
|
18
|
+ String contextPath = servletContext.getInitParameter("contextConfigLocation");
|
|
19
|
+ ApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextPath);
|
|
20
|
+ servletContext.setAttribute("app",applicationContext);
|
19
|
21
|
System.out.println("servletContextLoader");
|
20
|
22
|
}
|
21
|
|
-
|
|
23
|
+ @Override
|
22
|
24
|
public void contextDestroyed(ServletContextEvent sce) {
|
23
|
|
-
|
24
|
25
|
}
|
25
|
26
|
}
|