0

I have configured bootstrap.yml for spring config

spring:
  application:
    name: cce-auth
  cloud:
    config:
      uri: http://temp.com:8888

It works fine but I need URI value Dynamically, for example if I will publish this .war in test environment this URL must be http://test-temp.com:8888.

So for this I have solution create config.txt file in server and using I/O Stream reed/write this string to bootstrap.yml.

But problem is loading, spring loads http://localhost:8888 before I'm writing in bootstrap.yml.

So my reason is to create dynamically URI for config server. DO you have any idea?

Jessica Rodriguez
  • 2,899
  • 1
  • 12
  • 27
ZURA Tikaradze
  • 279
  • 5
  • 15
  • use a substitution and let boot do it `uri: {$config.server.url}`. And set that as a system property or environment variable. – spencergibb Apr 03 '19 at 15:49

1 Answers1

1

Define active_profile in bootstrap.yml file

spring:
  profiles:
    active: ${activatedProperties}

Then create bootstrap-${activatedProperties}.yml for each environment, etc..bootstrap-dev.yml, bootstrap-pre.yml, bootstrap-prod.yml

For example:

spring:
  application:
    name: servicename_prod
  cloud:
    config:
      uri: https://admin:123456@test.com:8888
server:
  port: 8443

add plugin to pom.xml file :

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

When run java, define environment on it: for example, run with prod environment.

java -Dserver.port=8443 -Dspring.profiles.active=prod -jar ....
Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53