Hi JuanManual32
Many thanks for your help - this seems to do the trick.The loader makes the WebApplicationContext available resolving both the XmlViewResolver and RequestContext errors I was seeing and the dependancyinjection works.
Here's your ContextLoader with a couple of tweaks :
Code:
public class MyContextLoader extends AbstractContextLoader {
protected static final Log logger = LogFactory.getLog(MyContextLoader.class);
public static final ServletContext SERVLET_CONTEXT = new MockServletContext("/WebContent", new FileSystemResourceLoader());
protected BeanDefinitionReader createBeanDefinitionReader(final GenericApplicationContext context) {
return new XmlBeanDefinitionReader(context);
}
public final ConfigurableApplicationContext loadContext(final String... locations) throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("Loading ApplicationContext for locations ["
+ StringUtils.arrayToCommaDelimitedString(locations) + "].");
}
final GenericWebApplicationContext webContext = new GenericWebApplicationContext();
SERVLET_CONTEXT.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext);
webContext.setServletContext(SERVLET_CONTEXT);
createBeanDefinitionReader(webContext).loadBeanDefinitions(locations);
AnnotationConfigUtils.registerAnnotationConfigProcessors(webContext);
webContext.refresh();
webContext.registerShutdownHook();
return webContext;
}
protected String getResourceSuffix() {
return "-context.xml";
}
}
and a test snippet .....
Code:
@RunWith(.....
@ContextConfiguration(loader=MyContextLoader.class, locations={"classpath:my-application-context.xml"})
public class MyControllerTest extends AbstractTransactionalJUnit4SpringContextTests {
@Autowired
protected hplMetricsController hplMetricsController;
private ServletContext servletContext;
private MockPageContext pageContext;
private MockServletConfig servletConfig;
private MockHttpSession session;
private MockHttpServletRequest request;
private MockHttpServletResponse response;
private WebApplicationContext wac;
@Test
public void setupMocks() throws Exception {
wac = WebApplicationContextUtils.getRequiredWebApplicationContext(MyContextLoader.SERVLET_CONTEXT);
servletContext = wac.getServletContext();
pageContext = new MockPageContext(servletContext);
servletConfig = (MockServletConfig) pageContext.getServletConfig();
session = (MockHttpSession)pageContext.getSession();
request = (MockHttpServletRequest) pageContext.getRequest();
response = (MockHttpServletResponse)pageContext.getResponse();
Thanks to everyone for their time and assistance....... Geoff