use of org.springframework.web.context.support.XmlWebApplicationContext in project spring-framework by spring-projects.
the class SimpleUrlHandlerMappingTests method handlerBeanNotFound.
@Test
public void handlerBeanNotFound() throws Exception {
MockServletContext sc = new MockServletContext("");
XmlWebApplicationContext root = new XmlWebApplicationContext();
root.setServletContext(sc);
root.setConfigLocations(new String[] { "/org/springframework/web/servlet/handler/map1.xml" });
root.refresh();
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.setParent(root);
wac.setServletContext(sc);
wac.setNamespace("map2err");
wac.setConfigLocations(new String[] { "/org/springframework/web/servlet/handler/map2err.xml" });
try {
wac.refresh();
fail("Should have thrown NoSuchBeanDefinitionException");
} catch (FatalBeanException ex) {
NoSuchBeanDefinitionException nestedEx = (NoSuchBeanDefinitionException) ex.getCause();
assertEquals("mainControlle", nestedEx.getBeanName());
}
}
use of org.springframework.web.context.support.XmlWebApplicationContext in project spring-framework by spring-projects.
the class EnvironmentSystemIntegrationTests method xmlWebApplicationContext.
@Test
public void xmlWebApplicationContext() {
AbstractRefreshableWebApplicationContext ctx = new XmlWebApplicationContext();
ctx.setConfigLocation("classpath:" + XML_PATH);
ctx.setEnvironment(prodWebEnv);
ctx.refresh();
assertHasEnvironment(ctx, prodWebEnv);
assertEnvironmentBeanRegistered(ctx);
assertEnvironmentAwareInvoked(ctx, prodWebEnv);
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
use of org.springframework.web.context.support.XmlWebApplicationContext in project simple-java by angryziber.
the class SpringAwareResource method autowire.
public static void autowire(ServletContext sc, Object target) {
XmlWebApplicationContext context = (XmlWebApplicationContext) WebApplicationContextUtils.getWebApplicationContext(sc);
context.getBeanFactory().autowireBean(target);
}
use of org.springframework.web.context.support.XmlWebApplicationContext in project spring-security by spring-projects.
the class HttpInterceptUrlTests method loadConfig.
private void loadConfig(String... configLocations) {
for (int i = 0; i < configLocations.length; i++) {
configLocations[i] = getClass().getName().replaceAll("\\.", "/") + "-" + configLocations[i];
}
XmlWebApplicationContext context = new XmlWebApplicationContext();
context.setConfigLocations(configLocations);
context.setServletContext(new MockServletContext());
context.refresh();
this.context = context;
context.getAutowireCapableBeanFactory().autowireBean(this);
Filter springSecurityFilterChain = context.getBean("springSecurityFilterChain", Filter.class);
mockMvc = MockMvcBuilders.standaloneSetup(new FooController()).addFilters(springSecurityFilterChain).build();
}
use of org.springframework.web.context.support.XmlWebApplicationContext in project spring-framework by spring-projects.
the class XmlWebApplicationContextTests method createContext.
@Override
protected ConfigurableApplicationContext createContext() throws Exception {
InitAndIB.constructed = false;
root = new XmlWebApplicationContext();
root.getEnvironment().addActiveProfile("rootProfile1");
MockServletContext sc = new MockServletContext("");
root.setServletContext(sc);
root.setConfigLocations(new String[] { "/org/springframework/web/context/WEB-INF/applicationContext.xml" });
root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
if (bean instanceof TestBean) {
((TestBean) bean).getFriends().add("myFriend");
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
return bean;
}
});
}
});
root.refresh();
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.getEnvironment().addActiveProfile("wacProfile1");
wac.setParent(root);
wac.setServletContext(sc);
wac.setNamespace("test-servlet");
wac.setConfigLocations(new String[] { "/org/springframework/web/context/WEB-INF/test-servlet.xml" });
wac.refresh();
return wac;
}
Aggregations