org.springframework.cloud.context.scope.refresh.RefreshScope Java Examples
The following examples show how to use
org.springframework.cloud.context.scope.refresh.RefreshScope.
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: RefreshScopeHealthIndicator.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@Override protected void doHealthCheck(Builder builder) throws Exception { RefreshScope refreshScope = this.scope.getIfAvailable(); if (refreshScope != null) { Map<String, Exception> errors = new HashMap<>(refreshScope.getErrors()); errors.putAll(this.rebinder.getErrors()); if (errors.isEmpty()) { builder.up(); } else { builder.down(); if (errors.size() == 1) { builder.withException(errors.values().iterator().next()); } else { for (String name : errors.keySet()) { builder.withDetail(name, errors.get(name)); } } } } }
Example #2
Source File: SpelSupportTest.java From config-toolkit with Apache License 2.0 | 6 votes |
public static void main(String[] args) { try (final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:config-toolkit-simple.xml")) { context.registerShutdownHook(); context.start(); ExampleBeanWithSpel bean = context.getBean(ExampleBeanWithSpel.class); GeneralConfigGroup cg1 = (GeneralConfigGroup) context.getBean("propertyGroup1"); cg1.register(new IObserver() { @Override public void notified(String data, String value) { context.getBean(RefreshScope.class).refresh("exampleBeanWithSpel"); } }); while (true) { bean.someMethod(); try { Thread.sleep(1000); } catch (InterruptedException e) { } } } }
Example #3
Source File: RefreshEndpointTests.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@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(); then(keys.contains("external.message")).isTrue().as("Wrong keys: " + keys); }
Example #4
Source File: RefreshEndpointTests.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@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(); then(keys.contains("external.message")).as("Wrong keys: " + keys).isFalse(); }
Example #5
Source File: RefreshScopedRetryAutoConfiguration.java From resilience4j with Apache License 2.0 | 5 votes |
/** * @param retryConfigurationProperties retry spring configuration properties * @param retryEventConsumerRegistry the retry event consumer registry * @return the RefreshScoped RetryRegistry */ @Bean @org.springframework.cloud.context.config.annotation.RefreshScope @ConditionalOnMissingBean public RetryRegistry retryRegistry(RetryConfigurationProperties retryConfigurationProperties, EventConsumerRegistry<RetryEvent> retryEventConsumerRegistry, RegistryEventConsumer<Retry> retryRegistryEventConsumer, @Qualifier("compositeRetryCustomizer") CompositeCustomizer<RetryConfigCustomizer> compositeRetryCustomizer) { return retryConfiguration .retryRegistry(retryConfigurationProperties, retryEventConsumerRegistry, retryRegistryEventConsumer, compositeRetryCustomizer); }
Example #6
Source File: RefreshEndpointAutoConfiguration.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean @ConditionalOnEnabledHealthIndicator("refresh") RefreshScopeHealthIndicator refreshScopeHealthIndicator( ObjectProvider<RefreshScope> scope, ConfigurationPropertiesRebinder rebinder) { return new RefreshScopeHealthIndicator(scope, rebinder); }
Example #7
Source File: RefreshEndpointTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@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); this.context.getEnvironment().setActiveProfiles("local"); ContextRefresher contextRefresher = new ContextRefresher(this.context, scope); RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher); Collection<String> keys = endpoint.refresh(); then(keys.contains("added")).isTrue().as("Wrong keys: " + keys); }
Example #8
Source File: RefreshEndpointTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@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); this.context.getEnvironment().setActiveProfiles("override"); ContextRefresher contextRefresher = new ContextRefresher(this.context, scope); RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher); Collection<String> keys = endpoint.refresh(); then(keys.contains("message")).isTrue().as("Wrong keys: " + keys); }
Example #9
Source File: ScmContextRefresher.java From super-cloudops with Apache License 2.0 | 5 votes |
public ScmContextRefresher(ConfigurableApplicationContext context, RefreshScope scope) { super(context, scope); Assert.notNull(context, "ApplicationContext must not be null"); Assert.notNull(scope, "RefreshScope must not be null"); this.context = context; this.scope = scope; }
Example #10
Source File: RefreshScopedRateLimiterAutoConfiguration.java From resilience4j with Apache License 2.0 | 5 votes |
/** * @param rateLimiterProperties ratelimiter spring configuration properties * @param rateLimiterEventsConsumerRegistry the ratelimiter event consumer registry * @return the RefreshScoped RateLimiterRegistry */ @Bean @org.springframework.cloud.context.config.annotation.RefreshScope @ConditionalOnMissingBean public RateLimiterRegistry rateLimiterRegistry( RateLimiterConfigurationProperties rateLimiterProperties, EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry, RegistryEventConsumer<RateLimiter> rateLimiterRegistryEventConsumer, @Qualifier("compositeRateLimiterCustomizer") CompositeCustomizer<RateLimiterConfigCustomizer> compositeRateLimiterCustomizer) { return rateLimiterConfiguration.rateLimiterRegistry( rateLimiterProperties, rateLimiterEventsConsumerRegistry, rateLimiterRegistryEventConsumer, compositeRateLimiterCustomizer); }
Example #11
Source File: RefreshEndpointTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@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(); then(2).isEqualTo(after).as("Shutdown hooks not cleaned on refresh"); then(empty.events.get(0) instanceof EnvironmentChangeEvent).isTrue(); }
Example #12
Source File: RefreshScopedBulkheadAutoConfiguration.java From resilience4j with Apache License 2.0 | 5 votes |
/** * @param threadPoolBulkheadConfigurationProperties thread pool bulkhead spring configuration * properties * @param bulkheadEventConsumerRegistry the bulk head event consumer registry * @return the RefreshScoped ThreadPoolBulkheadRegistry */ @Bean @org.springframework.cloud.context.config.annotation.RefreshScope @ConditionalOnMissingBean public ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry( ThreadPoolBulkheadConfigurationProperties threadPoolBulkheadConfigurationProperties, EventConsumerRegistry<BulkheadEvent> bulkheadEventConsumerRegistry, RegistryEventConsumer<ThreadPoolBulkhead> threadPoolBulkheadRegistryEventConsumer, @Qualifier("compositeThreadPoolBulkheadCustomizer") CompositeCustomizer<ThreadPoolBulkheadConfigCustomizer> compositeThreadPoolBulkheadCustomizer) { return threadPoolBulkheadConfiguration.threadPoolBulkheadRegistry( threadPoolBulkheadConfigurationProperties, bulkheadEventConsumerRegistry, threadPoolBulkheadRegistryEventConsumer, compositeThreadPoolBulkheadCustomizer); }
Example #13
Source File: RefreshScopedBulkheadAutoConfiguration.java From resilience4j with Apache License 2.0 | 5 votes |
/** * @param bulkheadConfigurationProperties bulkhead spring configuration properties * @param bulkheadEventConsumerRegistry the bulkhead event consumer registry * @return the RefreshScoped BulkheadRegistry */ @Bean @org.springframework.cloud.context.config.annotation.RefreshScope @ConditionalOnMissingBean public BulkheadRegistry bulkheadRegistry( BulkheadConfigurationProperties bulkheadConfigurationProperties, EventConsumerRegistry<BulkheadEvent> bulkheadEventConsumerRegistry, RegistryEventConsumer<Bulkhead> bulkheadRegistryEventConsumer, @Qualifier("compositeBulkheadCustomizer") CompositeCustomizer<BulkheadConfigCustomizer> compositeBulkheadCustomizer) { return bulkheadConfiguration .bulkheadRegistry(bulkheadConfigurationProperties, bulkheadEventConsumerRegistry, bulkheadRegistryEventConsumer, compositeBulkheadCustomizer); }
Example #14
Source File: RefreshScopedCircuitBreakerAutoConfiguration.java From resilience4j with Apache License 2.0 | 5 votes |
/** * @param eventConsumerRegistry the circuit breaker event consumer registry * @return the RefreshScoped CircuitBreakerRegistry */ @Bean @org.springframework.cloud.context.config.annotation.RefreshScope @ConditionalOnMissingBean public CircuitBreakerRegistry circuitBreakerRegistry( EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry, RegistryEventConsumer<CircuitBreaker> circuitBreakerRegistryEventConsumer, @Qualifier("compositeCircuitBreakerCustomizer") CompositeCustomizer<CircuitBreakerConfigCustomizer> compositeCircuitBreakerCustomizer) { return circuitBreakerConfiguration .circuitBreakerRegistry(eventConsumerRegistry, circuitBreakerRegistryEventConsumer, compositeCircuitBreakerCustomizer); }
Example #15
Source File: RefreshEndpointTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Test public void shutdownHooksCleaned() { try (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(); then(count).isEqualTo(after).as("Shutdown hooks not cleaned on refresh"); } }
Example #16
Source File: LocalApolloApplication.java From apollo with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { /** * Common */ ConfigurableApplicationContext commonContext = new SpringApplicationBuilder(ApolloApplication.class).web(WebApplicationType.NONE).run(args); logger.info(commonContext.getId() + " isActive: " + commonContext.isActive()); /** * ConfigService */ if (commonContext.getEnvironment().containsProperty("configservice")) { ConfigurableApplicationContext configContext = new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext) .sources(RefreshScope.class).run(args); logger.info(configContext.getId() + " isActive: " + configContext.isActive()); } /** * AdminService */ if (commonContext.getEnvironment().containsProperty("adminservice")) { ConfigurableApplicationContext adminContext = new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext) .sources(RefreshScope.class).run(args); logger.info(adminContext.getId() + " isActive: " + adminContext.isActive()); } /** * Portal */ if (commonContext.getEnvironment().containsProperty("portal")) { ConfigurableApplicationContext portalContext = new SpringApplicationBuilder(PortalApplication.class).parent(commonContext).run(args); logger.info(portalContext.getId() + " isActive: " + portalContext.isActive()); } }
Example #17
Source File: ApolloApplication.java From apollo with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { /** * Common */ ConfigurableApplicationContext commonContext = new SpringApplicationBuilder(ApolloApplication.class).web(WebApplicationType.NONE).run(args); logger.info(commonContext.getId() + " isActive: " + commonContext.isActive()); /** * ConfigService */ if (commonContext.getEnvironment().containsProperty("configservice")) { ConfigurableApplicationContext configContext = new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext) .sources(RefreshScope.class).run(args); logger.info(configContext.getId() + " isActive: " + configContext.isActive()); } /** * AdminService */ if (commonContext.getEnvironment().containsProperty("adminservice")) { ConfigurableApplicationContext adminContext = new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext) .sources(RefreshScope.class).run(args); logger.info(adminContext.getId() + " isActive: " + adminContext.isActive()); } /** * Portal */ if (commonContext.getEnvironment().containsProperty("portal")) { ConfigurableApplicationContext portalContext = new SpringApplicationBuilder(PortalApplication.class).parent(commonContext) .sources(RefreshScope.class).run(args); logger.info(portalContext.getId() + " isActive: " + portalContext.isActive()); } }
Example #18
Source File: EurekaClientAutoConfiguration.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Bean @org.springframework.cloud.context.config.annotation.RefreshScope @ConditionalOnBean(AutoServiceRegistrationProperties.class) @ConditionalOnProperty( value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient, CloudEurekaInstanceConfig instanceConfig, ApplicationInfoManager applicationInfoManager, @Autowired( required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) { return EurekaRegistration.builder(instanceConfig).with(applicationInfoManager) .with(eurekaClient).with(healthCheckHandler).build(); }
Example #19
Source File: ContextRefresher.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
protected RefreshScope getScope() { return this.scope; }
Example #20
Source File: RefreshScopeHealthIndicatorTests.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
@Test public void nullRefreshScope() { ObjectProvider<RefreshScope> scopeProvider = mock(ObjectProvider.class); BDDMockito.willReturn(null).given(scopeProvider).getIfAvailable(); then(this.indicator.health().getStatus()).isEqualTo(Status.UP); }
Example #21
Source File: RefreshScopeHealthIndicator.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
public RefreshScopeHealthIndicator(ObjectProvider<RefreshScope> scope, ConfigurationPropertiesRebinder rebinder) { this.scope = scope; this.rebinder = rebinder; }
Example #22
Source File: RefreshAutoConfiguration.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
@Bean @ConditionalOnMissingBean public ContextRefresher contextRefresher(ConfigurableApplicationContext context, RefreshScope scope) { return new ContextRefresher(context, scope); }
Example #23
Source File: RefreshAutoConfiguration.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
@Bean @ConditionalOnMissingBean(RefreshScope.class) public static RefreshScope refreshScope() { return new RefreshScope(); }
Example #24
Source File: ContextRefresher.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
public ContextRefresher(ConfigurableApplicationContext context, RefreshScope scope) { this.context = context; this.scope = scope; }
Example #25
Source File: ZookeeperPropertySourceLocatorTests.java From spring-cloud-zookeeper with Apache License 2.0 | 4 votes |
@Bean public ContextRefresher contextRefresher(ConfigurableApplicationContext context, RefreshScope scope) { return new ContextRefresher(context, scope); }
Example #26
Source File: RefreshScopedTimeLimiterAutoConfiguration.java From resilience4j with Apache License 2.0 | 4 votes |
/** * @return the RefreshScoped TimeLimiterRegistry */ @Bean @org.springframework.cloud.context.config.annotation.RefreshScope @ConditionalOnMissingBean public TimeLimiterRegistry timeLimiterRegistry( TimeLimiterConfigurationProperties timeLimiterProperties, EventConsumerRegistry<TimeLimiterEvent> timeLimiterEventsConsumerRegistry, RegistryEventConsumer<TimeLimiter> timeLimiterRegistryEventConsumer, @Qualifier("compositeTimeLimiterCustomizer") CompositeCustomizer<TimeLimiterConfigCustomizer> compositeTimeLimiterCustomizer) { return timeLimiterConfiguration.timeLimiterRegistry( timeLimiterProperties, timeLimiterEventsConsumerRegistry, timeLimiterRegistryEventConsumer, compositeTimeLimiterCustomizer); }
Example #27
Source File: TestConfig.java From spring-cloud-deployer-mesos with Apache License 2.0 | 4 votes |
@Bean @ConditionalOnMissingBean public static RefreshScope refreshScope() { return new RefreshScope(); }
Example #28
Source File: SpringBootApolloRefreshConfig.java From apollo with Apache License 2.0 | 4 votes |
public SpringBootApolloRefreshConfig( final SampleRedisConfig sampleRedisConfig, final RefreshScope refreshScope) { this.sampleRedisConfig = sampleRedisConfig; this.refreshScope = refreshScope; }
Example #29
Source File: ScmClientAutoConfiguration.java From super-cloudops with Apache License 2.0 | 2 votes |
/** * See:{@link RefreshAutoConfiguration#contextRefresher()} * * @param context * @param scope * @return */ @Bean public ContextRefresher scmContextRefresher(ConfigurableApplicationContext context, RefreshScope scope) { return new ScmContextRefresher(context, scope); }