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
spring boot configuration are ok. then go to consul ui using localhost:8500 and select key/value and add key value like below
then create it.then create configuration are like below
then restart your springboot application. your port change to 8084.
note: you can use YMAL or GIT2consul for more configuration