Distributed Configuration with HashiCorp Consul and Spring Boot -


i wonder how share properties in hashicorp consul using spring boot, read there's dependency 'spring-cloud-consul-config' not find how load folder properties files there.

using spring cloud config server possible, example:

spring:     profiles:     active: native   cloud:     config:       server:         native:            searchlocations: file:c:/springbootapp/properties/ 

but, how in spring cloud config consul?

assuming have consul running on standard port there not configuration needed using spring boot. whole code pasted below (no other configuration files).

the tricky part me figure out how key/values should stored in consul in order visible spring boot app. there information in documentation little bit misleading think.

to answer question put values under key "config/bootstrap/key1" inside consul make following example work.

here sample code worked me:

pom.xml

<dependency>     <groupid>org.springframework.boot</groupid>     <artifactid>spring-boot-starter-web</artifactid>     <version>1.3.1.release</version> </dependency> <dependency>     <groupid>org.springframework.cloud</groupid>     <artifactid>spring-cloud-starter-consul-all</artifactid>     <version>1.0.0.m5</version> </dependency> 

application.java

@springbootapplication @enablediscoveryclient @restcontroller public class application {      @autowired     private environment env;      @requestmapping("/")     public string home() {         return env.getproperty("key1");     }      public static void main(string[] args) {         new springapplicationbuilder(application.class).web(true).run(args);     }  } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -