Java 类org.springframework.web.context.support.XmlWebApplicationContext 实例源码

项目:springboot-shiro-cas-mybatis    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:springboot-shiro-cas-mybatis    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/webappContext.xml",
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:springboot-shiro-cas-mybatis    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/cas-management-servlet.xml",
            "classpath:/managementConfigContext.xml",
            "classpath:/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return WiringTests.class.getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:springboot-shiro-cas-mybatis    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:cas4.0.x-server-wechat    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:cas4.0.x-server-wechat    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:cas-server-4.2.1    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/webappContext.xml",
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:cas-server-4.2.1    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/cas-management-servlet.xml",
            "classpath:/managementConfigContext.xml",
            "classpath:/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return WiringTests.class.getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:spring4-understanding    文件:SimpleUrlHandlerMappingTests.java   
@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());
    }
}
项目:spring4-understanding    文件:XmlWebApplicationContextTests.java   
@Test
@SuppressWarnings("resource")
public void withoutMessageSource() 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));
}
项目:spring4-understanding    文件:ContextLoaderTests.java   
@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));
}
项目:quartzdesk-executor    文件:SpringProfilesActivator.java   
@Override
public void initialize( XmlWebApplicationContext applicationContext )
{
  ConfigurableEnvironment env = applicationContext.getEnvironment();

  WorkDir workDir;
  try
  {
    workDir = new WorkDir( applicationContext.getServletContext() );
  }
  catch ( IOException e )
  {
    throw new ApplicationContextException( "Error obtaining QuartzDesk Executor work directory.", e );
  }

  String databaseProfile = getDatabaseProfile( workDir );

  String[] activeProfiles = new String[] { databaseProfile };

  log.info( "Activating Spring profiles: {}", Arrays.toString( activeProfiles ) );

  env.setActiveProfiles( activeProfiles );
}
项目:aws-serverless-java-container    文件:LambdaHandler.java   
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context)
{
     if (!isinitialized) {
         isinitialized = true;
         try {
            XmlWebApplicationContext wc = new XmlWebApplicationContext();
            wc.setConfigLocation("classpath:/staticAppContext.xml");
             handler = SpringLambdaContainerHandler.getAwsProxyHandler(wc);
         } catch (ContainerInitializationException e) {
             e.printStackTrace();
             return null;
         }
     }
     AwsProxyResponse res = handler.proxy(awsProxyRequest, context);
     return res;
}
项目:cas-server-webapp    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:nbone    文件:SpringWebApplicationInitializer.java   
/**
* <p>默认关闭<p>
* 加载spring mvc 统一调度器
* @param servletContext
*/
  protected void initDispatcherServlet(ServletContext servletContext){
    String enable  = servletContext.getInitParameter("enableDispatcherServlet");
    if(BooleanUtils.valueOf(enable)){
        //classpath*:/spring-mvc*.xml,/WEB-INF/spring-mvc*.xml
        XmlWebApplicationContext appContext = new XmlWebApplicationContext();
        appContext.setConfigLocation("classpath*:/spring/spring-mvc*.xml,/WEB-INF/spring/spring-mvc*.xml");


        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(appContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");

    }

  }
项目:cas4.1.9    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:cas4.1.9    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:communote-server    文件:DispatcherServletInitializer.java   
private void createMainDispatcherServlet(ApplicationContext rootContext) {
    mainWebApplicationContext = new XmlWebApplicationContext();
    mainWebApplicationContext
            .setConfigLocation(getRequiredInitParameter("communoteWebContextConfigLocation"));
    mainWebApplicationContext.setParent(rootContext);
    // add ContextLoaderListener with web-ApplicationContext which publishes it under a
    // ServletContext attribute and closes it on shutdown. The former is required for
    // WebApplicationContextUtils which are used by DelegatingFilterProxy (spring security).
    // Closing is also done by dispatcher servlet's implementation of destroy method.
    this.servletContext.addListener(new ContextLoaderListener(mainWebApplicationContext));
    DispatcherServlet dispatcherServlet = new DispatcherServlet(mainWebApplicationContext);
    ServletRegistration.Dynamic addedServlet = this.servletContext.addServlet(
            getInitParameter("communoteServletName", "communote"), dispatcherServlet);
    addedServlet.setLoadOnStartup(1);
    addedServlet.addMapping(getRequiredInitParameter("communoteServletUrlPattern"));
    this.mainDispatcherServlet = dispatcherServlet;
}
项目:kc-rice    文件:SpringResourceLoader.java   
@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();
    }
}
项目:cas-4.0.1    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:cas-4.0.1    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:openmeetings    文件:InstallWizard.java   
@Override
protected void onSubmit() {
    try {
        ConnectionPropertiesPatcher.patch(getModelObject());
        XmlWebApplicationContext ctx = (XmlWebApplicationContext)getWebApplicationContext(Application.get().getServletContext());
        if (ctx == null) {
            form.error(new StringResourceModel("install.wizard.db.step.error.patch", InstallWizard.this).setParameters("Web context is NULL").getObject());
            log.error("Web context is NULL");
            return;
        }
        LocalEntityManagerFactoryBean emb = ctx.getBeanFactory().getBean(LocalEntityManagerFactoryBean.class);
        emb.afterPropertiesSet();
        dbType = getModelObject().getDbType();
    } catch (Exception e) {
        form.error(new StringResourceModel("install.wizard.db.step.error.patch", InstallWizard.this).setParameters(e.getMessage()).getObject());
        log.error("error while patching", e);
    }
}
项目:p00    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:p00    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:cas-server-4.0.1    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:cas-server-4.0.1    文件:WiringTests.java   
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
项目:starter-kit-spring-maven    文件:ServletInitializer.java   
@Override
public void onStartup(ServletContext container) throws ServletException {
    XmlWebApplicationContext context = new XmlWebApplicationContext();

    context.setConfigLocations(CONTEXT_CONFIG_LOCATIONS);

    DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
    dispatcherServlet.setPublishContext(true);

    FilterRegistration.Dynamic sessionFilter = container.addFilter("sessionFilter", new DelegatingFilterProxy("sessionFilter"));

    sessionFilter.addMappingForUrlPatterns(null, false, "*.jsp");

    this.servlets.stream().forEach( servlet -> {
        addServlet(container, sessionFilter, servlet);
    });
}
项目:gwt-sl    文件:HandlerTest.java   
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    ServletContext servletContext = new MockServletContext(
            new FileSystemResourceLoader());
    requestService = new MockHttpServletRequest("PUT", "/service");
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setServletContext(servletContext);
    applicationContext.setConfigLocations(new String[] {
            "src/main/webapp/WEB-INF/handler-servlet.xml",
            "src/main/webapp/WEB-INF/applicationContext.xml" });
    try{
    applicationContext.refresh();
    }
    catch (Throwable e){
        e.printStackTrace();
    }
    handler = (GWTHandler) applicationContext.getBean("urlMapping", GWTHandler.class);
}
项目:gwt-sl    文件:TestRPCExporter.java   
@Override
@Before
public void setUp() throws Exception {

    requestPayload = readResource("request_add.txt");
    responsePayload = readResource("response_add.txt");
    MockServletContext servletContext = new MockServletContext(new ResourceLoaderSupport());
    MockServletConfig servletConfig = new MockServletConfig(servletContext);
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setServletContext(servletContext);
    applicationContext.setServletConfig(servletConfig);
    applicationContext.setConfigLocations(new String[] { "src/main/webapp/WEB-INF/exporter-servlet.xml",
            "src/main/webapp/WEB-INF/applicationContext.xml" });
    applicationContext.refresh();
    handlerMapping = (SimpleUrlHandlerMapping) applicationContext
            .getBean("org.springframework.web.servlet.handler.SimpleUrlHandlerMapping");
}
项目:class-guard    文件:SimpleUrlHandlerMappingTests.java   
@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());
    }
}
项目:class-guard    文件:XmlWebApplicationContextTests.java   
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));
}
项目:class-guard    文件:ContextLoaderTests.java   
@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));
}
项目:rice    文件:SpringResourceLoader.java   
@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    文件:Rsine.java   
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;
}
项目:kuali_rice    文件:SpringResourceLoader.java   
@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();
    }
}
项目:dhus-core    文件:TestContextLoader.java   
@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;
}
项目:OperatieBRP    文件:BrpApplicatieStartListener.java   
@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);
    }


}
项目:Webstore    文件:AppInitializer.java   
@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("/");
}
项目:dwr    文件:DwrControllerTest.java   
/**
 * 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;
}
项目:spring4-understanding    文件:ControllerClassNameHandlerMappingTests.java   
@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");
}