当前位置: 首页>>代码示例>>Java>>正文


Java ConfigurableWebApplicationContext类代码示例

本文整理汇总了Java中org.springframework.web.context.ConfigurableWebApplicationContext的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableWebApplicationContext类的具体用法?Java ConfigurableWebApplicationContext怎么用?Java ConfigurableWebApplicationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConfigurableWebApplicationContext类属于org.springframework.web.context包,在下文中一共展示了ConfigurableWebApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
/**
 * Instantiate the WebApplicationContext for this servlet, either a default
 * {@link org.springframework.web.context.support.XmlWebApplicationContext}
 * or a {@link #setContextClass custom context class}, if set.
 * <p>This implementation expects custom contexts to implement the
 * {@link org.springframework.web.context.ConfigurableWebApplicationContext}
 * interface. Can be overridden in subclasses.
 * <p>Do not forget to register this servlet instance as application listener on the
 * created context (for triggering its {@link #onRefresh callback}, and to call
 * {@link org.springframework.context.ConfigurableApplicationContext#refresh()}
 * before returning the context instance.
 * @param parent the parent ApplicationContext to use, or {@code null} if none
 * @return the WebApplicationContext for this servlet
 * @see org.springframework.web.context.support.XmlWebApplicationContext
 */
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
	Class<?> contextClass = getContextClass();
	if (this.logger.isDebugEnabled()) {
		this.logger.debug("Servlet with name '" + getServletName() +
				"' will try to create custom WebApplicationContext context of class '" +
				contextClass.getName() + "'" + ", using parent context [" + parent + "]");
	}
	if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
		throw new ApplicationContextException(
				"Fatal initialization error in servlet with name '" + getServletName() +
				"': custom WebApplicationContext class [" + contextClass.getName() +
				"] is not of type ConfigurableWebApplicationContext");
	}
	ConfigurableWebApplicationContext wac =
			(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);

	wac.setEnvironment(getEnvironment());
	wac.setParent(parent);
	wac.setConfigLocation(getContextConfigLocation());

	configureAndRefreshWebApplicationContext(wac);

	return wac;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:FrameworkServlet.java

示例2: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
@Override
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Servlet with name '" + getServletName() +
                "' will try to create custom WebApplicationContext context of class '" +
                CubaXmlWebApplicationContext.class.getName() + "'" + ", using parent context [" + parent + "]");
    }
    ConfigurableWebApplicationContext wac = new CubaXmlWebApplicationContext() {
        @Override
        protected ResourcePatternResolver getResourcePatternResolver() {
            if (dependencyJars == null || dependencyJars.isEmpty()) {
                throw new RuntimeException("No JARs defined for the 'web' block. " +
                        "Please check that web.dependencies file exists in WEB-INF directory.");
            }
            return new SingleAppResourcePatternResolver(this, dependencyJars);
        }
    };

    wac.setEnvironment(getEnvironment());
    wac.setParent(parent);
    wac.setConfigLocation(getContextConfigLocation());

    configureAndRefreshWebApplicationContext(wac);

    return wac;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:27,代码来源:SingleAppDispatcherServlet.java

示例3: postProcessApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
/**
 * Apply any relevant post processing the {@link ApplicationContext}. Subclasses can
 * apply additional processing as required.
 * @param context the application context
 */
protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
	if (this.webEnvironment) {
		if (context instanceof ConfigurableWebApplicationContext) {
			ConfigurableWebApplicationContext configurableContext = (ConfigurableWebApplicationContext) context;
			if (this.beanNameGenerator != null) {
				configurableContext.getBeanFactory().registerSingleton(
						AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
						this.beanNameGenerator);
			}
		}
	}
	if (this.resourceLoader != null) {
		if (context instanceof GenericApplicationContext) {
			((GenericApplicationContext) context)
					.setResourceLoader(this.resourceLoader);
		}
		if (context instanceof DefaultResourceLoader) {
			((DefaultResourceLoader) context)
					.setClassLoader(this.resourceLoader.getClassLoader());
		}
	}
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:28,代码来源:SpringApplication.java

示例4: postProcessApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
/**
 * Apply any relevant post processing the {@link ApplicationContext}. Subclasses can
 * apply additional processing as required.
 * @param context the application context
 */
protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
	if (this.webEnvironment) {
		if (context instanceof ConfigurableWebApplicationContext) {
			ConfigurableWebApplicationContext configurableContext = (ConfigurableWebApplicationContext) context;
			if (this.beanNameGenerator != null) {
				configurableContext.getBeanFactory().registerSingleton(
						AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
						this.beanNameGenerator);
			}
		}
	}

	if (this.resourceLoader != null) {
		if (context instanceof GenericApplicationContext) {
			((GenericApplicationContext) context)
					.setResourceLoader(this.resourceLoader);
		}
		if (context instanceof DefaultResourceLoader) {
			((DefaultResourceLoader) context)
					.setClassLoader(this.resourceLoader.getClassLoader());
		}
	}
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:29,代码来源:SpringApplication.java

示例5: initWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
/**
   * Allows loading/override of custom bean definitions from sakai.home
   *
   * <p>The pattern is the 'servlet_name-context.xml'</p>
   *
   * @param servletContext current servlet context
   * @return the new WebApplicationContext
   * @throws org.springframework.beans.BeansException
   *          if the context couldn't be initialized
   */
  @Override
  public WebApplicationContext initWebApplicationContext(ServletContext servletContext) throws BeansException {

      ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) super.initWebApplicationContext(servletContext);
      // optionally look in sakai home for additional bean deifinitions to load
if (cwac != null) {
	final String servletName = servletContext.getServletContextName(); 
	String location = getHomeBeanDefinitionIfExists(servletName);
	if (StringUtils.isNotBlank(location)) {
		log.debug("Servlet " + servletName + " is attempting to load bean definition [" + location + "]");
		XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) cwac.getBeanFactory());
		try {
			int loaded = reader.loadBeanDefinitions(new FileSystemResource(location));
			log.info("Servlet " + servletName + " loaded " + loaded + " beans from [" + location + "]");
			AnnotationConfigUtils.registerAnnotationConfigProcessors(reader.getRegistry());
			cwac.getBeanFactory().preInstantiateSingletons();
		} catch (BeanDefinitionStoreException bdse) {
			log.warn("Failure loading beans from [" + location + "]", bdse);
		} catch (BeanCreationException bce) {
			log.warn("Failure instantiating beans from [" + location + "]", bce);
		}
	}
}
      return cwac;
  }
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:36,代码来源:SakaiContextLoader.java

示例6: customizeContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
@Override
protected void customizeContext(ServletContext servletContext,
        ConfigurableWebApplicationContext applicationContext) {
    super.customizeContext(servletContext, applicationContext);
    String policy = servletContext.getInitParameter("superfly-policy");
    if (policy == null) {
        policy = Policy.NONE.getIdentifier();
    }
    String disableHotp = servletContext.getInitParameter("disable-hotp");
    if ("true".equals(disableHotp)) {
        policy = Policy.NONE.getIdentifier();
    }
    String[] oldLocations = applicationContext.getConfigLocations();
    String[] newLocations = new String[oldLocations.length];
    for (int i = 0; i < oldLocations.length; i++) {
        newLocations[i] = oldLocations[i].replaceAll("\\!policy\\!", policy);
    }
    applicationContext.setConfigLocations(newLocations);
}
 
开发者ID:payneteasy,项目名称:superfly,代码行数:20,代码来源:CustomContextLoaderListener.java

示例7: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
    Class<?> contextClass = getContextClass();
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Servlet with name '" + getServletName() +
                "' will try to create custom WebApplicationContext context of class '" +
                contextClass.getName() + "'" + ", using parent context [" + parent + "]");
    }
    if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
        throw new ApplicationContextException(
                "Fatal initialization error in servlet with name '" + getServletName() +
                "': custom WebApplicationContext class [" + contextClass.getName() +
                "] is not of type ConfigurableWebApplicationContext");
    }
    ConfigurableWebApplicationContext wac =
            (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
    
    wac.setParent(parent);
    if (wac.getParent() == null) {
        ApplicationContext rootContext = (ApplicationContext) getServletContext().getAttribute("JetStreamRoot");
        wac.setParent(rootContext);
    }
    wac.setConfigLocation(getContextConfigLocation());
    configureAndRefreshWebApplicationContext(wac);
    return wac;
}
 
开发者ID:pulsarIO,项目名称:realtime-analytics,代码行数:26,代码来源:MetricDispatcherServlet.java

示例8: initialize

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
@Override
public void initialize(ConfigurableWebApplicationContext ctx) {
	try {
		this.setLocations(ctx.getResources("/WEB-INF/application-customer-dev.properties"));

		Properties props = this.mergeProperties();
		if (props.containsKey(TERRACOTTA_URL_KEY)) {
			System.setProperty(TERRACOTTA_URL_KEY, props.getProperty(TERRACOTTA_URL_KEY));
		}

		ctx.getEnvironment().getPropertySources().addLast(new PropertiesPropertySource("default_properties", props));

		this.setLocations(ctx.getResources("classpath:application-customer.properties"));

		props = this.mergeProperties();
		if (props.containsKey(TERRACOTTA_URL_KEY)) {
			System.setProperty(TERRACOTTA_URL_KEY, props.getProperty(TERRACOTTA_URL_KEY));
		}

		ctx.getEnvironment().getPropertySources()
				.addFirst(new PropertiesPropertySource("environment_properties", props));
	} catch (IOException e) {
		logger.info("Unable to load properties file.", e);
	}
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:26,代码来源:ContextProfileInitializer.java

示例9: initialize

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
@Override
public void initialize(ConfigurableWebApplicationContext ctx) {
	try {
		this.setLocations(ctx.getResources("/WEB-INF/application-batch-dev.properties"));

		Properties props = this.mergeProperties();
		if (props.containsKey(TERRACOTTA_URL_KEY)) {
			System.setProperty(TERRACOTTA_URL_KEY, props.getProperty(TERRACOTTA_URL_KEY));
		}

		ctx.getEnvironment().getPropertySources().addLast(new PropertiesPropertySource("default_properties", props));

		this.setLocations(ctx.getResources("classpath:application-batch.properties"));

		props = this.mergeProperties();
		if (props.containsKey(TERRACOTTA_URL_KEY)) {
			System.setProperty(TERRACOTTA_URL_KEY, props.getProperty(TERRACOTTA_URL_KEY));
		}

		ctx.getEnvironment().getPropertySources()
				.addFirst(new PropertiesPropertySource("environment_properties", props));
	} catch (IOException e) {
		logger.info("Unable to load properties file.", e);
	}
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:26,代码来源:ContextProfileInitializer.java

示例10: test_no_register_after_close

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void test_no_register_after_close() {
    ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
    TaskScheduler scheduler = mock(TaskScheduler.class);
    RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);

    ScheduledFuture task = mock(ScheduledFuture.class);
    when(scheduler.scheduleAtFixedRate(isA(Runnable.class), eq(Duration.ofSeconds(10)))).thenReturn(task);

    listener.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), null,
            mock(ConfigurableWebApplicationContext.class)));

    verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), eq(Duration.ofSeconds(10)));

    listener.onClosedContext(new ContextClosedEvent(mock(WebApplicationContext.class)));
    verify(task).cancel(true);
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:19,代码来源:RegistrationApplicationListenerTest.java

示例11: customizeContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
protected void customizeContext(ServletContext servletContext,
		ConfigurableWebApplicationContext applicationContext) {
	String[] configLocations = applicationContext.getConfigLocations();
	String[] jresConfigLocations = null;
	if (configLocations == null || configLocations.length < 1) {
		configLocations = StringUtils.tokenizeToStringArray(
				servletContext.getInitParameter(CONFIG_LOCATION_PARAM),
				",; \t\n");
	}
	if (configLocations != null) {
		jresConfigLocations = new String[configLocations.length + 2];
		jresConfigLocations[0] = "classpath:conf/spring/jres-web-beans.xml";
		jresConfigLocations[1] = "classpath:conf/spring/jres-common-beans.xml";
		int index = 2;
		for (String config : configLocations) {
			jresConfigLocations[index] = config;
			index++;
		}

	}
	applicationContext.setConfigLocations(jresConfigLocations);
	super.customizeContext(servletContext, applicationContext);
}
 
开发者ID:xiyelife,项目名称:jresplus,代码行数:24,代码来源:ContextLoaderListener.java

示例12: closeWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
/**
 * Close Spring's web application context for the given servlet context. If
 * the default {@link #loadParentContext(ServletContext)} implementation,
 * which uses ContextSingletonBeanFactoryLocator, has loaded any shared
 * parent context, release one reference to that shared parent context.
 * <p>If overriding {@link #loadParentContext(ServletContext)}, you may have
 * to override this method as well.
 * @param servletContext the ServletContext that the WebApplicationContext runs in
 */
public void closeWebApplicationContext(ServletContext servletContext) {
    servletContext.log("Closing Spring root WebApplicationContext");
    try {
        if (this.context instanceof ConfigurableWebApplicationContext) {
            ((ConfigurableWebApplicationContext) this.context).close();
        }
    }
    finally {
        currentContextPerThread.remove(Thread.currentThread().getContextClassLoader());
        servletContext.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        if (this.parentContextRef != null) {
            this.parentContextRef.release();
        }
    }
}
 
开发者ID:code4craft,项目名称:tavern,代码行数:25,代码来源:SpringTavernContextLoader.java

示例13: addDataSourceProfile

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
private void addDataSourceProfile(ConfigurableWebApplicationContext ctx) {
    DataSourceConfigType dataSourceConfigType;
    String rawType = ctx.getEnvironment().getProperty(DATASOURCE_CONFIG_TYPE);
    if(StringUtils.isNotBlank(rawType)) {
        dataSourceConfigType = DataSourceConfigType.valueOf(StringUtils.upperCase(rawType));
    } else {
        dataSourceConfigType = DataSourceConfigType.LEGACY;
    }
    String dataSourceTypeProfile = StringUtils.lowerCase(dataSourceConfigType.name());
    List<String> existingProfiles = Lists.newArrayList(ctx.getEnvironment().getActiveProfiles());
    existingProfiles.add(dataSourceTypeProfile);
    ctx.getEnvironment().setActiveProfiles(existingProfiles.toArray(new String[0]));
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:14,代码来源:CustomPropertySourceConfigurer.java

示例14: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
protected WebApplicationContext createWebApplicationContext(ServletContext sc, ApplicationContext parent)
{
	GenericWebApplicationContext wac = (GenericWebApplicationContext) BeanUtils.instantiateClass(GenericWebApplicationContext.class);

	// Assign the best possible id value.
	wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + contextPath);

	wac.setParent(parent);
	wac.setServletContext(sc);
	wac.refresh();

	return wac;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:14,代码来源:AbstractJettyComponent.java

示例15: configureAndRefreshWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入依赖的package包/类
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) {
	if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
		// The application context id is still set to its original default value
		// -> assign a more useful id based on available information
		if (this.contextId != null) {
			wac.setId(this.contextId);
		}
		else {
			// Generate default id...
			wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
					ObjectUtils.getDisplayString(getServletContext().getContextPath()) + "/" + getServletName());
		}
	}

	wac.setServletContext(getServletContext());
	wac.setServletConfig(getServletConfig());
	wac.setNamespace(getNamespace());
	wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));

	// The wac environment's #initPropertySources will be called in any case when the context
	// is refreshed; do it eagerly here to ensure servlet property sources are in place for
	// use in any post-processing or initialization that occurs below prior to #refresh
	ConfigurableEnvironment env = wac.getEnvironment();
	if (env instanceof ConfigurableWebEnvironment) {
		((ConfigurableWebEnvironment) env).initPropertySources(getServletContext(), getServletConfig());
	}

	postProcessWebApplicationContext(wac);
	applyInitializers(wac);
	wac.refresh();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:32,代码来源:FrameworkServlet.java


注:本文中的org.springframework.web.context.ConfigurableWebApplicationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。