Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consul key value pair use for configuration in Spring-boot

I tried to change my registration server from "Eureka" to "Consul" and also Consul as my config server. Service discovery with Consul is a success.But I can't understand how to get key/value pair option to bootstrap my application. Is there any possible way I can do that?

I use spring boot with below dependancies

<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>

and this is my spring boot app ConsuleDemoApplication.class

@EnableDiscoveryClient
@SpringBootApplication
@RestController
public class ConsuleDemoApplication {

    @RequestMapping("/")
    public String home() {
        return "Hello world";
    }

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

and my bootstrap.yml is

spring:
  cloud:
    consul:
      discovery:
        healthCheckInterval: 15s
        instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}

  application:
    name: consul_demo
like image 706
wthamira Avatar asked Sep 12 '26 06:09

wthamira


1 Answers

spring boot configuration are ok. then go to consul ui using localhost:8500 and select key/value and add key value like below

enter image description here

then create it.then create configuration are like below

enter image description here

then restart your springboot application. your port change to 8084.

note: you can use YMAL or GIT2consul for more configuration

like image 191
wthamira Avatar answered Sep 14 '26 19:09

wthamira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!