本文整理汇总了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"));
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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);
}
示例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);
}