2017-03-02 2 views
2

Ich habe eine Spring-Boot-Anwendung und ich möchte Eigenschaften, die ich auf einem Konsul-Agent haben.Spring Boot Eigenschaften von Konsul-Server

@EnableDiscoveryClient 
@SpringBootApplication(scanBasePackages={"com.commons"}) 
public class MainAppProxy implements CommandLineRunner {  
    @Value("${proxy.endpoint}") 
    private String endpointAddress; 

Mein application.properties ist unter src/main/resources

spring.application.name=SOAPProxy 
spring.cloud.consul.host=http://10.0.1.241 
spring.cloud.consul.port=8500 
spring.cloud.config.discovery.enabled=false 

in pom.xml habe ich die folgende Konfiguration (Kurzfassung)

  <artifactId>spring-cloud-dependencies</artifactId> 
      <version>Camden.SR5</version> 
     <groupId>org.springframework.cloud</groupId> 
     <artifactId>spring-cloud-starter-config</artifactId> 

Die Eigenschaften auf gespeichert werden Konsul in diesem Format: Business/SOAPProxy/proxy.endpoint

Wenn die Anwendung bootet, es scheint, dass es Konsul findet, aber es kann nicht die Werte erhalten, wie es vor dem Versuch konnte Konsul @ Value ("$ {proxy.endpoint}") Wie kann ich die Eigenschaften auf Consul bekommen?

+0

tun Sie Konfiguration von Konsul bekommen müssen? – wthamira

Antwort

1

Sie drei Wege können Konfiguration von Konsul

  1. Schlüssel/Wert
  2. yaml
  3. Datei Konfiguration zu laden

ich in yaml verwendet zu laden.

Dies ist meine bootstrap.yml Datei (Sie können auch .property Datei verwenden können)

spring: 
    application: 
    name: SOAPProxy 

--- 

spring: 
    profiles: default 
    cloud: 
    consul: 
     config: 
     data-key: data 
     prefix: config 
     format: yaml 
     host: localhost 
     port: 8500 
     discovery: 
     prefer-ip-address: true 

mein Boot-App wie Beschriften unter

@EnableDiscoveryClient 
@EnableAutoConfiguration 
@SpringBootApplication 
public class SpringBootConsulApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(SpringBootConsulApplication.class, args); 
    } 
} 

Maven dependancy

<dependency> 
    <groupId>org.springframework.cloud</groupId> 
    <artifactId>spring-cloud-starter-consul-config</artifactId> 
</dependency> 

<dependency> 
    <groupId>org.springframework.cloud</groupId> 
    <artifactId>spring-cloud-starter-consul-discovery</artifactId> 
</dependency> 
wie folgt hinzufügen

Dies ist die Konfiguration des Consul Agent Key/Wert

enter image description here

jetzt in Start alle Konfigurations Last auf die Anwendung

Verwandte Themen