1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.appstatus.web;
17
18 import javax.servlet.ServletContext;
19
20 import net.sf.appstatus.core.IObjectInstantiationListener;
21
22 import org.springframework.beans.BeansException;
23 import org.springframework.web.context.WebApplicationContext;
24 import org.springframework.web.context.support.WebApplicationContextUtils;
25
26
27
28
29
30
31
32
33 public class SpringObjectInstantiationListener implements
34 IObjectInstantiationListener {
35 WebApplicationContext webApplicationContext = null;
36
37
38
39
40
41
42
43 public SpringObjectInstantiationListener(ServletContext context) {
44 webApplicationContext = WebApplicationContextUtils
45 .getRequiredWebApplicationContext(context);
46 }
47
48 public Object getInstance(String className) {
49 Object obj = null;
50
51 try {
52 obj = webApplicationContext.getBean(className);
53 } catch (BeansException e) {
54 }
55
56 return obj;
57 }
58
59 }