public void testWithoutMessageSource() throws Exception {
MockServletContext sc = new MockServletContext("");
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.setParent(root);
wac.setServletContext(sc);
wac.setNamespace("testNamespace");
wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"});
wac.refresh();
try {
wac.getMessage("someMessage", null, Locale.getDefault());
fail("Should have thrown NoSuchMessageException");
}
catch (NoSuchMessageException ex) {
// expected;
}
String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault());
assertTrue("Default message returned", "default".equals(msg));
}
java类org.springframework.web.context.support.XmlWebApplicationContext的实例源码
XmlWebApplicationContextTests.java 文件源码
项目:class-guard
阅读 16
收藏 0
点赞 0
评论 0
ContextLoaderTests.java 文件源码
项目:class-guard
阅读 24
收藏 0
点赞 0
评论 0
@Test
public void testContextLoaderListenerWithDefaultContext() {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
"/org/springframework/web/context/WEB-INF/applicationContext.xml " +
"/org/springframework/web/context/WEB-INF/context-addition.xml");
ServletContextListener listener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
listener.contextInitialized(event);
WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
assertTrue("Correct WebApplicationContext exposed in ServletContext", context instanceof XmlWebApplicationContext);
assertTrue(WebApplicationContextUtils.getRequiredWebApplicationContext(sc) instanceof XmlWebApplicationContext);
LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
assertTrue("Has father", context.containsBean("father"));
assertTrue("Has rod", context.containsBean("rod"));
assertTrue("Has kerry", context.containsBean("kerry"));
assertTrue("Not destroyed", !lb.isDestroyed());
assertFalse(context.containsBean("beans1.bean1"));
assertFalse(context.containsBean("beans1.bean2"));
listener.contextDestroyed(event);
assertTrue("Destroyed", lb.isDestroyed());
assertNull(sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
assertNull(WebApplicationContextUtils.getWebApplicationContext(sc));
}
SpringResourceLoader.java 文件源码
项目:rice
阅读 16
收藏 0
点赞 0
评论 0
@Override
public void start() throws Exception {
if(!isStarted()){
LOG.info("Creating Spring context " + StringUtils.join(this.fileLocs, ","));
if (parentSpringResourceLoader != null && parentContext != null) {
throw new ConfigurationException("Both a parentSpringResourceLoader and parentContext were defined. Only one can be defined!");
}
if (parentSpringResourceLoader != null) {
parentContext = parentSpringResourceLoader.getContext();
}
if (servletContextcontext != null) {
XmlWebApplicationContext lContext = new XmlWebApplicationContext();
lContext.setServletContext(servletContextcontext);
lContext.setParent(parentContext);
lContext.setConfigLocations(this.fileLocs.toArray(new String[] {}));
lContext.refresh();
context = lContext;
} else {
this.context = new ClassPathXmlApplicationContext(this.fileLocs.toArray(new String[] {}), parentContext);
}
super.start();
}
}
Rsine.java 文件源码
项目:rsine
阅读 15
收藏 0
点赞 0
评论 0
private static Server startServer() throws Exception {
Server server = new Server(cmdParams.port);
XmlWebApplicationContext context = new XmlWebApplicationContext();
context.setConfigLocation("classpath:application-context.xml");
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setContextPath("/");
contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), "/*");
contextHandler.addEventListener(new ContextLoaderListener(context));
server.setHandler(contextHandler);
server.start();
return server;
}
SpringResourceLoader.java 文件源码
项目:kuali_rice
阅读 18
收藏 0
点赞 0
评论 0
@Override
public void start() throws Exception {
if(!isStarted()){
LOG.info("Creating Spring context " + StringUtils.join(this.fileLocs, ","));
if (parentSpringResourceLoader != null && parentContext != null) {
throw new ConfigurationException("Both a parentSpringResourceLoader and parentContext were defined. Only one can be defined!");
}
if (parentSpringResourceLoader != null) {
parentContext = parentSpringResourceLoader.getContext();
}
if (servletContextcontext != null) {
XmlWebApplicationContext lContext = new XmlWebApplicationContext();
lContext.setServletContext(servletContextcontext);
lContext.setParent(parentContext);
lContext.setConfigLocations(this.fileLocs.toArray(new String[] {}));
lContext.refresh();
context = lContext;
} else {
this.context = new ClassPathXmlApplicationContext(this.fileLocs.toArray(new String[] {}), parentContext);
}
super.start();
}
}
TestContextLoader.java 文件源码
项目:dhus-core
阅读 16
收藏 0
点赞 0
评论 0
@Override
public ApplicationContext loadContext (String... locations) throws Exception
{
XmlWebApplicationContext ctx = new XmlWebApplicationContext ();
ctx.setConfigLocations (locations);
ctx.getEnvironment ().setActiveProfiles ("test");
ctx.refresh ();
AnnotationConfigUtils.registerAnnotationConfigProcessors (
(BeanDefinitionRegistry) ctx.getBeanFactory ());
ctx.registerShutdownHook ();
return ctx;
}
BrpApplicatieStartListener.java 文件源码
项目:OperatieBRP
阅读 18
收藏 0
点赞 0
评论 0
@Override
public final void onApplicationEvent(final ApplicationContextEvent event) {
try {
final ApplicationContext context = event.getApplicationContext();
if (context instanceof XmlWebApplicationContext) {
final XmlWebApplicationContext ctx = (XmlWebApplicationContext) context;
String webContextName = ctx.getServletContext().getServletContextName();
if (webContextName.contains("/")) {
webContextName = webContextName.substring(webContextName.indexOf('/'));
}
ctx.setDisplayName(webContextName);
MDC.put(LeveringVeld.MDC_APPLICATIE_NAAM, webContextName).close();
}
LOGGER.debug("Context event '{}'; id='{}', displayName='{}'", event.getClass().getSimpleName(), event
.getApplicationContext().getId(), event.getApplicationContext().getDisplayName());
if (event instanceof ContextClosedEvent) {
LOGGER.info("==> Context voor applicatie '{}' is gestopt", event.getApplicationContext().getId());
}
/* Wanneer een applicatie is gestart, dan wordt een ContextRefreshedEvent gestuurt **/
if (event instanceof ContextRefreshedEvent) {
LOGGER.info("==> Context voor applicatie '{}' is gestart/herstart", event.getApplicationContext()
.getId());
logJvmSettings();
}
} catch (final ApplicationContextException ex) {
LOGGER.error("Fout bij het opstarten van de applicatiecontext bij event {}", event.toString(), ex);
}
}
AppInitializer.java 文件源码
项目:Webstore
阅读 37
收藏 0
点赞 0
评论 0
@Override
public void onStartup(ServletContext container) throws ServletException {
XmlWebApplicationContext appContext = new XmlWebApplicationContext();
appContext.setConfigLocation("/WEB-INF/spring/webcontext/DispatcherServlet-context.xml");
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(appContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
DwrControllerTest.java 文件源码
项目:dwr
阅读 15
收藏 0
点赞 0
评论 0
/**
* Subclasses can invoke this to get a context key for the given location.
* This doesn't affect the applicationContext instance variable in this class.
* Dependency Injection cannot be applied from such contexts.
*/
//@Override
protected ConfigurableApplicationContext loadContextLocations(String[] locations)
{
log.info("Loading my own config for: " + StringUtils.arrayToCommaDelimitedString(locations));
XmlWebApplicationContext ctx = new XmlWebApplicationContext();
ctx.setConfigLocations(locations);
ctx.setServletContext(new MockServletContext());
ctx.refresh();
return ctx;
}
ControllerClassNameHandlerMappingTests.java 文件源码
项目:spring4-understanding
阅读 17
收藏 0
点赞 0
评论 0
@Before
public void setUp() throws Exception {
MockServletContext sc = new MockServletContext("");
this.wac = new XmlWebApplicationContext();
this.wac.setServletContext(sc);
this.wac.setConfigLocations(new String[] {LOCATION});
this.wac.refresh();
this.hm = (HandlerMapping) this.wac.getBean("mapping");
this.hm2 = (HandlerMapping) this.wac.getBean("mapping2");
this.hm3 = (HandlerMapping) this.wac.getBean("mapping3");
this.hm4 = (HandlerMapping) this.wac.getBean("mapping4");
}