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


Java RefreshScope.setApplicationContext方法代码示例

本文整理汇总了Java中org.springframework.cloud.context.scope.refresh.RefreshScope.setApplicationContext方法的典型用法代码示例。如果您正苦于以下问题:Java RefreshScope.setApplicationContext方法的具体用法?Java RefreshScope.setApplicationContext怎么用?Java RefreshScope.setApplicationContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.cloud.context.scope.refresh.RefreshScope的用法示例。


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

示例1: keysComputedWhenChangesInExternalProperties

import org.springframework.cloud.context.scope.refresh.RefreshScope; //导入方法依赖的package包/类
@Test
public void keysComputedWhenChangesInExternalProperties() throws Exception {
	this.context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF)
			.properties("spring.cloud.bootstrap.name:none").run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(this.context);
	TestPropertyValues
			.of("spring.cloud.bootstrap.sources="
					+ ExternalPropertySourceLocator.class.getName())
			.applyTo(this.context.getEnvironment(), Type.MAP, "defaultProperties");
	ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	Collection<String> keys = endpoint.refresh();
	assertTrue("Wrong keys: " + keys, keys.contains("external.message"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:17,代码来源:RefreshEndpointTests.java

示例2: springMainSourcesEmptyInRefreshCycle

import org.springframework.cloud.context.scope.refresh.RefreshScope; //导入方法依赖的package包/类
@Test
public void springMainSourcesEmptyInRefreshCycle() throws Exception {
	this.context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF)
			.properties("spring.cloud.bootstrap.name:none").run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(this.context);
	// spring.main.sources should be empty when the refresh cycle starts (we don't
	// want any config files from the application context getting into the one used to
	// construct the environment for refresh)
	TestPropertyValues
			.of("spring.main.sources="
					+ ExternalPropertySourceLocator.class.getName())
			.applyTo(this.context);
	ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	Collection<String> keys = endpoint.refresh();
	assertFalse("Wrong keys: " + keys, keys.contains("external.message"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:20,代码来源:RefreshEndpointTests.java

示例3: keysComputedWhenAdded

import org.springframework.cloud.context.scope.refresh.RefreshScope; //导入方法依赖的package包/类
@Test
public void keysComputedWhenAdded() throws Exception {
	this.context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF)
			.properties("spring.cloud.bootstrap.name:none").run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(this.context);
	context.getEnvironment().setActiveProfiles("local");
	ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	Collection<String> keys = endpoint.refresh();
	assertTrue("Wrong keys: " + keys, keys.contains("added"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:14,代码来源:RefreshEndpointTests.java

示例4: keysComputedWhenOveridden

import org.springframework.cloud.context.scope.refresh.RefreshScope; //导入方法依赖的package包/类
@Test
public void keysComputedWhenOveridden() throws Exception {
	this.context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF)
			.properties("spring.cloud.bootstrap.name:none").run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(this.context);
	context.getEnvironment().setActiveProfiles("override");
	ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	Collection<String> keys = endpoint.refresh();
	assertTrue("Wrong keys: " + keys, keys.contains("message"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:14,代码来源:RefreshEndpointTests.java

示例5: eventsPublishedInOrder

import org.springframework.cloud.context.scope.refresh.RefreshScope; //导入方法依赖的package包/类
@Test
public void eventsPublishedInOrder() throws Exception {
	this.context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF).run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(this.context);
	ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	Empty empty = this.context.getBean(Empty.class);
	endpoint.refresh();
	int after = empty.events.size();
	assertEquals("Shutdown hooks not cleaned on refresh", 2, after);
	assertTrue(empty.events.get(0) instanceof EnvironmentChangeEvent);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:15,代码来源:RefreshEndpointTests.java

示例6: shutdownHooksCleaned

import org.springframework.cloud.context.scope.refresh.RefreshScope; //导入方法依赖的package包/类
@Test
public void shutdownHooksCleaned() {
	ConfigurableApplicationContext context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF).run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(context);
	ContextRefresher contextRefresher = new ContextRefresher(context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	int count = countShutdownHooks();
	endpoint.refresh();
	int after = countShutdownHooks();
	assertEquals("Shutdown hooks not cleaned on refresh", count, after);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:14,代码来源:RefreshEndpointTests.java


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