1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.oness.common.webapp.controller.action;
17
18 import org.apache.struts.action.ActionServlet;
19 import org.springframework.context.ApplicationContext;
20 import org.springframework.web.context.support.WebApplicationContextUtils;
21
22 /***
23 * Loads Spring Application Context and exposes its beans
24 *
25 * @author Carlos Sanchez
26 * @version $Revision: 1.1 $
27 */
28 public class SpringActionSupport {
29
30 private ApplicationContext ctx = null;
31
32 private ActionServlet actionServlet = null;
33
34 public SpringActionSupport(ActionServlet actionServlet) {
35 this.actionServlet = actionServlet;
36 }
37
38 /***
39 * Gets a bean from Spring configuration
40 *
41 * @param name
42 * bean name
43 * @return the bean
44 */
45 public Object getBean(String name) {
46 if (ctx == null) {
47 ctx = WebApplicationContextUtils
48 .getRequiredWebApplicationContext(actionServlet
49 .getServletContext());
50 }
51 return ctx.getBean(name);
52 }
53
54 }