Java Code Examples for org.springframework.web.context.support.XmlWebApplicationContext#setConfigLocation()

The following examples show how to use org.springframework.web.context.support.XmlWebApplicationContext#setConfigLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LambdaHandler.java    From aws-serverless-java-container with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: DispatcherServletChannelInitializer.java    From nettyholdspringmvc with Apache License 2.0 6 votes vote down vote up
public DispatcherServletChannelInitializer() throws ServletException {

    	MockServletContext servletContext = new MockServletContext();
    	MockServletConfig servletConfig = new MockServletConfig(servletContext);
        servletConfig.addInitParameter("contextConfigLocation","classpath:/META-INF/spring/root-context.xml");
        servletContext.addInitParameter("contextConfigLocation","classpath:/META-INF/spring/root-context.xml");

    	//AnnotationConfigWebApplicationContext wac = new AnnotationConfigWebApplicationContext();
        XmlWebApplicationContext wac = new XmlWebApplicationContext();

        //ClassPathXmlApplicationContext wac = new ClassPathXmlApplicationContext();
		wac.setServletContext(servletContext);
		wac.setServletConfig(servletConfig);
        wac.setConfigLocation("classpath:/servlet-context.xml");
    	//wac.register(WebConfig.class);
    	wac.refresh();

    	this.dispatcherServlet = new DispatcherServlet(wac);
    	this.dispatcherServlet.init(servletConfig);
	}
 
Example 3
Source File: IbisApplicationInitializer.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
protected WebApplicationContext createWebApplicationContext(ServletContext servletContext) {
	System.setProperty(EndpointImpl.CHECK_PUBLISH_ENDPOINT_PERMISSON_PROPERTY_WITH_SECURITY_MANAGER, "false");
	servletContext.log("Starting IBIS WebApplicationInitializer");

	XmlWebApplicationContext applicationContext = new XmlWebApplicationContext();
	applicationContext.setConfigLocation(XmlWebApplicationContext.CLASSPATH_URL_PREFIX + "/webApplicationContext.xml");
	applicationContext.setDisplayName("IbisApplicationInitializer");

	MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
	propertySources.remove(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
	propertySources.remove(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
	propertySources.addFirst(new PropertiesPropertySource("ibis", AppConstants.getInstance()));

	return applicationContext;
}
 
Example 4
Source File: WebAppInitializer.java    From tutorials with MIT License 6 votes vote down vote up
public void onStartup(ServletContext container) throws ServletException {

        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
        ctx.register(WebMvcConfigure.class);
        ctx.setServletContext(container);

        ServletRegistration.Dynamic servletOne = container.addServlet("SpringProgrammaticDispatcherServlet", new DispatcherServlet(ctx));
        servletOne.setLoadOnStartup(1);
        servletOne.addMapping("/");

        XmlWebApplicationContext xctx = new XmlWebApplicationContext();
        xctx.setConfigLocation("/WEB-INF/context.xml");
        xctx.setServletContext(container);

        ServletRegistration.Dynamic servletTwo = container.addServlet("SpringProgrammaticXMLDispatcherServlet", new DispatcherServlet(xctx));
        servletTwo.setLoadOnStartup(1);
        servletTwo.addMapping("/");
    }
 
Example 5
Source File: StreamingReceiver.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void startHttpServer() throws Exception {
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    createAndConfigHttpServer(kylinConfig);

    ContextHandlerCollection contexts = new ContextHandlerCollection();

    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/kylin");

    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setConfigLocation("classpath:applicationContext.xml");
    ctx.refresh();
    DispatcherServlet dispatcher = new DispatcherServlet(ctx);
    context.addServlet(new ServletHolder(dispatcher), "/api/*");

    ContextHandler logContext = new ContextHandler("/kylin/logs");
    String logDir = getLogDir(kylinConfig);
    ResourceHandler logHandler = new ResourceHandler();
    logHandler.setResourceBase(logDir);
    logHandler.setDirectoriesListed(true);
    logContext.setHandler(logHandler);

    contexts.setHandlers(new Handler[] { context, logContext });
    httpServer.setHandler(contexts);
    httpServer.start();
    httpServer.join();
}
 
Example 6
Source File: WebApplicationInitializerImpl.java    From artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    logger.info("===== Application is starting up! ========");

    try {
        XmlWebApplicationContext appContext = new XmlWebApplicationContext();
        appContext.setConfigLocation(APPLICATION_CONTEXT_FILE);

        ServletRegistration.Dynamic registration = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(appContext));
        registration.setLoadOnStartup(1);
        registration.addMapping(DISPATCHER_SERVLET_MAPPING);

        // allow cross domain
        Filters.registerCrossDomainFilter(servletContext, DISPATCHER_SERVLET_MAPPING);

        // allow put/delete method
        servletContext.addFilter(HIDDEN_HTTP_METHOD_FILTER_NAME, new HiddenHttpMethodFilter());

        Filters.registerCompressingFilter(servletContext, DISPATCHER_SERVLET_MAPPING);

        DataConfig.init();

        DiscoveryServiceImpl.getInstance().addFilters(GroupDiscoveryFilter.getInstance(), ManagementDiscoveryFilter.getInstance());

        ManagementRepository.getInstance().addFilter(GroupDiscoveryFilter.getInstance());

        ClusterManager.INSTANCE.init(Lists.<NodeInitializer> newArrayList(ManagementInitializer.INSTANCE));
    } catch (Throwable ex) {
        logger.error("WebApplicationInitalizer failed.", ex);
        ex.printStackTrace();
        throw new ServletException(ex);
    }
}
 
Example 7
Source File: StreamingReceiver.java    From kylin with Apache License 2.0 5 votes vote down vote up
private void startHttpServer() throws Exception {
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    createAndConfigHttpServer(kylinConfig);

    ContextHandlerCollection contexts = new ContextHandlerCollection();

    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/kylin");

    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setConfigLocation("classpath:applicationContext.xml");
    ctx.refresh();
    DispatcherServlet dispatcher = new DispatcherServlet(ctx);
    context.addServlet(new ServletHolder(dispatcher), "/api/*");

    ContextHandler logContext = new ContextHandler("/kylin/logs");
    String logDir = getLogDir(kylinConfig);
    ResourceHandler logHandler = new ResourceHandler();
    logHandler.setResourceBase(logDir);
    logHandler.setDirectoriesListed(true);
    logContext.setHandler(logHandler);

    contexts.setHandlers(new Handler[] { context, logContext });
    httpServer.setHandler(contexts);
    httpServer.start();
    httpServer.join();
}
 
Example 8
Source File: InterAccountSNSPermissionTest.java    From spring-integration-aws with MIT License 5 votes vote down vote up
private ServletContextHandler getServletContextHandler() throws Exception {

		context = new XmlWebApplicationContext();
		context.setConfigLocation("src/main/webapp/WEB-INF/InterAccountSNSPermissionFlow.xml");
		context.registerShutdownHook();

		ServletContextHandler contextHandler = new ServletContextHandler();
		contextHandler.setErrorHandler(null);
		contextHandler.setResourceBase(".");
		ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(
				context));
		contextHandler.addServlet(servletHolder, "/*");

		return contextHandler;
	}
 
Example 9
Source File: PetclinicInitializer.java    From DevOps-for-Web-Development with MIT License 4 votes vote down vote up
@Override
protected WebApplicationContext createServletApplicationContext() {
    XmlWebApplicationContext webAppContext = new XmlWebApplicationContext();
    webAppContext.setConfigLocation("classpath:spring/mvc-core-config.xml");
    return webAppContext;
}
 
Example 10
Source File: KualiInitializeListener.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * ServletContextListener interface implementation that schedules the start of the lifecycle
 */
@Override
public void contextInitialized(ServletContextEvent sce) {
    long startInit = System.currentTimeMillis();
    LOG.info("Initializing Kuali Rice Application...");

    // Stop Quartz from "phoning home" on every startup
    System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");

    List<String> configLocations = new ArrayList<String>();
    String additionalConfigLocations = System.getProperty(KewApiConstants.ADDITIONAL_CONFIG_LOCATIONS_PARAM);
    if (!StringUtils.isBlank(additionalConfigLocations)) {
        String[] additionalConfigLocationArray = additionalConfigLocations.split(",");
        for (String additionalConfigLocation : additionalConfigLocationArray) {
            configLocations.add(additionalConfigLocation);
        }
    }

    String bootstrapSpringBeans = "";
    if (!StringUtils.isBlank(System.getProperty(WEB_BOOTSTRAP_SPRING_FILE))) {
        bootstrapSpringBeans = System.getProperty(WEB_BOOTSTRAP_SPRING_FILE);
    } else if (!StringUtils.isBlank(sce.getServletContext().getInitParameter(WEB_BOOTSTRAP_SPRING_FILE))) {
        String bootstrapSpringInitParam = sce.getServletContext().getInitParameter(WEB_BOOTSTRAP_SPRING_FILE);
        // if the value comes through as ${bootstrap.spring.beans}, we ignore it
        if (!DEFAULT_SPRING_BEANS_REPLACEMENT_VALUE.equals(bootstrapSpringInitParam)) {
            bootstrapSpringBeans = bootstrapSpringInitParam;
            LOG.info("Found bootstrap Spring Beans file defined in servlet context: " + bootstrapSpringBeans);
        }
    }

    Properties baseProps = new Properties();
    baseProps.putAll(getContextParameters(sce.getServletContext()));
    baseProps.putAll(System.getProperties());
    JAXBConfigImpl config = new JAXBConfigImpl(baseProps);
    ConfigContext.init(config);

    context = new XmlWebApplicationContext();
    if (!StringUtils.isEmpty(bootstrapSpringBeans)) {
        context.setConfigLocation(bootstrapSpringBeans);
    }
    context.setServletContext(sce.getServletContext());

    // Provide an optional method for bootstrapping a Spring property source
    Optional<PropertySource<?>> ps = PropertySources.getPropertySource(sce, "web.bootstrap.spring.psc");
    if (ps.isPresent()) {
        PropertySources.addFirst(context, ps.get());
    }

    try {
        context.refresh();
    } catch (RuntimeException e) {
        LOG.error("problem during context.refresh()", e);

        throw e;
    }

    context.start();
    long endInit = System.currentTimeMillis();
    LOG.info("...Kuali Rice Application successfully initialized, startup took " + (endInit - startInit) + " ms.");
}