1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2;
22
23 import org.springframework.context.ApplicationContext;
24 import org.springframework.test.context.support.GenericXmlContextLoader;
25 import org.springframework.web.context.WebApplicationContext;
26
27 /***
28 * Base class for Spring JUnit actions
29 */
30 public abstract class StrutsSpringTestCase extends StrutsTestCase {
31 private static final String DEFAULT_CONTEXT_LOCATION = "classpath*:applicationContext.xml";
32 protected static ApplicationContext applicationContext;
33
34
35 protected void setupBeforeInitDispatcher() throws Exception {
36
37 GenericXmlContextLoader xmlContextLoader = new GenericXmlContextLoader();
38 applicationContext = xmlContextLoader.loadContext(getContextLocations());
39 servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
40 }
41
42 protected String getContextLocations() {
43 return DEFAULT_CONTEXT_LOCATION;
44 }
45 }