Search in sources :

Example 1 with ConfigDataLocation

use of org.springframework.boot.context.config.ConfigDataLocation in project spring-cloud-consul by spring-cloud.

the class ConsulConfigDataLocationResolver method resolveProfileSpecific.

@Override
public List<ConsulConfigDataResource> resolveProfileSpecific(ConfigDataLocationResolverContext resolverContext, ConfigDataLocation location, Profiles profiles) throws ConfigDataLocationNotFoundException {
    UriComponents locationUri = parseLocation(resolverContext, location);
    // create consul client
    registerBean(resolverContext, ConsulProperties.class, loadProperties(resolverContext, locationUri));
    registerAndPromoteBean(resolverContext, ConsulClient.class, this::createConsulClient);
    // create locations
    ConsulConfigProperties properties = loadConfigProperties(resolverContext);
    ConsulPropertySources consulPropertySources = new ConsulPropertySources(properties, log);
    List<Context> contexts = (locationUri == null || CollectionUtils.isEmpty(locationUri.getPathSegments())) ? consulPropertySources.generateAutomaticContexts(profiles.getAccepted(), false) : getCustomContexts(locationUri, properties);
    registerAndPromoteBean(resolverContext, ConsulConfigProperties.class, InstanceSupplier.of(properties));
    registerAndPromoteBean(resolverContext, ConsulConfigIndexes.class, InstanceSupplier.from(ConsulConfigDataIndexes::new));
    return contexts.stream().map(propertySourceContext -> new ConsulConfigDataResource(propertySourceContext.getPath(), properties, consulPropertySources, propertySourceContext.getProfile())).collect(Collectors.toList());
}
Also used : BootstrapContext(org.springframework.boot.BootstrapContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigDataLocationResolverContext(org.springframework.boot.context.config.ConfigDataLocationResolverContext) Context(org.springframework.cloud.consul.config.ConsulPropertySources.Context) ConfigurableBootstrapContext(org.springframework.boot.ConfigurableBootstrapContext) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Arrays(java.util.Arrays) BootstrapContext(org.springframework.boot.BootstrapContext) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Profiles(org.springframework.boot.context.config.Profiles) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigDataLocation(org.springframework.boot.context.config.ConfigDataLocation) Nullable(org.springframework.lang.Nullable) ConfigDataLocationResolverContext(org.springframework.boot.context.config.ConfigDataLocationResolverContext) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) ConfigDataLocationNotFoundException(org.springframework.boot.context.config.ConfigDataLocationNotFoundException) Bindable(org.springframework.boot.context.properties.bind.Bindable) ConsulClient(com.ecwid.consul.v1.ConsulClient) Context(org.springframework.cloud.consul.config.ConsulPropertySources.Context) ConfigurableBootstrapContext(org.springframework.boot.ConfigurableBootstrapContext) FILES(org.springframework.cloud.consul.config.ConsulConfigProperties.Format.FILES) Collectors(java.util.stream.Collectors) List(java.util.List) InstanceSupplier(org.springframework.boot.BootstrapRegistry.InstanceSupplier) ConsulAutoConfiguration(org.springframework.cloud.consul.ConsulAutoConfiguration) CollectionUtils(org.springframework.util.CollectionUtils) Log(org.apache.commons.logging.Log) Binder(org.springframework.boot.context.properties.bind.Binder) Collections(java.util.Collections) ConfigDataLocationResolver(org.springframework.boot.context.config.ConfigDataLocationResolver) ConsulProperties(org.springframework.cloud.consul.ConsulProperties) StringUtils(org.springframework.util.StringUtils) UriComponents(org.springframework.web.util.UriComponents) UriComponents(org.springframework.web.util.UriComponents)

Aggregations

ConsulClient (com.ecwid.consul.v1.ConsulClient)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Log (org.apache.commons.logging.Log)1 BootstrapContext (org.springframework.boot.BootstrapContext)1 InstanceSupplier (org.springframework.boot.BootstrapRegistry.InstanceSupplier)1 ConfigurableBootstrapContext (org.springframework.boot.ConfigurableBootstrapContext)1 ConfigDataLocation (org.springframework.boot.context.config.ConfigDataLocation)1 ConfigDataLocationNotFoundException (org.springframework.boot.context.config.ConfigDataLocationNotFoundException)1 ConfigDataLocationResolver (org.springframework.boot.context.config.ConfigDataLocationResolver)1 ConfigDataLocationResolverContext (org.springframework.boot.context.config.ConfigDataLocationResolverContext)1 Profiles (org.springframework.boot.context.config.Profiles)1 BindHandler (org.springframework.boot.context.properties.bind.BindHandler)1 Bindable (org.springframework.boot.context.properties.bind.Bindable)1 Binder (org.springframework.boot.context.properties.bind.Binder)1 ConsulAutoConfiguration (org.springframework.cloud.consul.ConsulAutoConfiguration)1