Skip to content

Commit

Permalink
Extract the Consul default-context field as a constant (#1538)
Browse files Browse the repository at this point in the history
  • Loading branch information
Song246 authored Jun 5, 2024
1 parent 38b4faf commit d77efe1
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class ConsulRefresherHandler extends AbstractConfigThreadPoolDynamicRefre

private static final int INITIAL_CAPACITY = 64;

private static final String DEFAULT_CONTEXT = "spring.cloud.consul.config.default-context";

@EventListener(EnvironmentChangeEvent.class)
public void refreshed(EnvironmentChangeEvent event) {
Map<String, Object> configInfo = extractLatestConfigInfo(event);
Expand Down Expand Up @@ -70,7 +72,7 @@ private Map<String, Object> extractLatestConfigInfo(EnvironmentChangeEvent event
private CharSequence getApplicationConfigDefaultContext(AbstractEnvironment environment) {
return environment.getPropertySources().stream()
.filter(propertySource -> propertySource instanceof OriginTrackedMapPropertySource)
.map(propertySource -> ((Map<String, CharSequence>) propertySource.getSource()).get("spring.cloud.consul.config.default-context"))
.map(propertySource -> ((Map<String, CharSequence>) propertySource.getSource()).get(DEFAULT_CONTEXT))
.findFirst().orElse(StringUtils.EMPTY);
}

Expand Down

0 comments on commit d77efe1

Please sign in to comment.