當前位置: 首頁>>代碼示例>>Java>>正文


Java GenericApplicationContext.setParent方法代碼示例

本文整理匯總了Java中org.springframework.context.support.GenericApplicationContext.setParent方法的典型用法代碼示例。如果您正苦於以下問題:Java GenericApplicationContext.setParent方法的具體用法?Java GenericApplicationContext.setParent怎麽用?Java GenericApplicationContext.setParent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.context.support.GenericApplicationContext的用法示例。


在下文中一共展示了GenericApplicationContext.setParent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: closingChildContextDoesNotCleanUpLoggingSystem

import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void closingChildContextDoesNotCleanUpLoggingSystem() {
	System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
			TestCleanupLoggingSystem.class.getName());
	this.initializer.onApplicationEvent(
			new ApplicationStartedEvent(this.springApplication, new String[0]));
	TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
			.getField(this.initializer, "loggingSystem");
	assertThat(loggingSystem.cleanedUp).isFalse();
	GenericApplicationContext childContext = new GenericApplicationContext();
	childContext.setParent(this.context);
	this.initializer.onApplicationEvent(new ContextClosedEvent(childContext));
	assertThat(loggingSystem.cleanedUp).isFalse();
	this.initializer.onApplicationEvent(new ContextClosedEvent(this.context));
	assertThat(loggingSystem.cleanedUp).isTrue();
	childContext.close();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:LoggingApplicationListenerTests.java

示例2: loadContext

import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
/**
 * Load a Spring ApplicationContext from the supplied {@link MergedContextConfiguration}.
 *
 * <p>Implementation details:
 *
 * <ul>
 * <li>Calls {@link #validateMergedContextConfiguration(MergedContextConfiguration)}
 * to allow subclasses to validate the supplied configuration before proceeding.</li>
 * <li>Creates a {@link GenericApplicationContext} instance.</li>
 * <li>If the supplied {@code MergedContextConfiguration} references a
 * {@linkplain MergedContextConfiguration#getParent() parent configuration},
 * the corresponding {@link MergedContextConfiguration#getParentApplicationContext()
 * ApplicationContext} will be retrieved and
 * {@linkplain GenericApplicationContext#setParent(ApplicationContext) set as the parent}
 * for the context created by this method.</li>
 * <li>Calls {@link #prepareContext(GenericApplicationContext)} for backwards
 * compatibility with the {@link org.springframework.test.context.ContextLoader
 * ContextLoader} SPI.</li>
 * <li>Calls {@link #prepareContext(ConfigurableApplicationContext, MergedContextConfiguration)}
 * to allow for customizing the context before bean definitions are loaded.</li>
 * <li>Calls {@link #customizeBeanFactory(DefaultListableBeanFactory)} to allow for customizing the
 * context's {@code DefaultListableBeanFactory}.</li>
 * <li>Delegates to {@link #loadBeanDefinitions(GenericApplicationContext, MergedContextConfiguration)}
 * to populate the context from the locations or classes in the supplied
 * {@code MergedContextConfiguration}.</li>
 * <li>Delegates to {@link AnnotationConfigUtils} for
 * {@link AnnotationConfigUtils#registerAnnotationConfigProcessors registering}
 * annotation configuration processors.</li>
 * <li>Calls {@link #customizeContext(GenericApplicationContext)} to allow for customizing the context
 * before it is refreshed.</li>
 * <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
 * context and registers a JVM shutdown hook for it.</li>
 * </ul>
 *
 * @return a new application context
 * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration)
 * @see GenericApplicationContext
 * @since 3.1
 */
@Override
public final ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Loading ApplicationContext for merged context configuration [%s].",
			mergedConfig));
	}

	validateMergedContextConfiguration(mergedConfig);

	GenericApplicationContext context = new GenericApplicationContext();

	ApplicationContext parent = mergedConfig.getParentApplicationContext();
	if (parent != null) {
		context.setParent(parent);
	}
	prepareContext(context);
	prepareContext(context, mergedConfig);
	customizeBeanFactory(context.getDefaultListableBeanFactory());
	loadBeanDefinitions(context, mergedConfig);
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	customizeContext(context);
	context.refresh();
	context.registerShutdownHook();
	return context;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:65,代碼來源:AbstractGenericContextLoader.java


注:本文中的org.springframework.context.support.GenericApplicationContext.setParent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。