2

Is there anyway to make spring cloud config client's application.yml read values from spring config server? For example, on my spring cloud config client, the application.yml is like this

spring:
  application:
  name: clienttest
mvc:
view:
  prefix: /jsp/
  suffix: .jsp


server: 
  port: 8080
  context-path: /clienttest
  tomcat:
   uri-encoding: UTF-8

eureka:
 client:
   service-url: {"defaultZone":"http://dev.euraka01.app.com:8769/eureka/,http://dev.euraka02.app.com:8770/eureka/"}
instance:
 prefer-ip-address: true

and my bootstrap.yml file is as below

spring:
  application:
    name: clienttest
  cloud:
    config:
      name: clienttest
      uri: http://192.168.2.101:9000
      enabled: true
      profile: out_test
      label: master

now for the service-url value, for different environment, I have to config different eureka url values, my question is that, is there anyway that I can config the service-url value in the config server? like I set the value as ${service-url} in the application.yml, and when I start the config client server, it get the value from the config server according the profile and label which I set in the bootstrap.yml.

Gary Zhang
  • 33
  • 3
  • 6

2 Answers2

1

You can look up properties on the config server by both profile and label, where label is either either a branch, tag.

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

In your example above your config server will try and find a file named

clienttest-out_test.properties

In the git repo on the master branch.

spring:
  application:
    name: clienttest
  cloud:
    config:
      profile: out_test
      label: master

See the example and also a good doc here

Essex Boy
  • 7,565
  • 2
  • 21
  • 24
0

Essex Boy, Thank you very much for your help, and I was able to read the value from different config profile before. My question is how to make application.yml get the value from config server, and now I've solve it by myself, the answer is quite easy, in the application, set value like ${service-url}, the full answer is as below:

in my application.yml, the content is as below:

spring:
  application:
  name: clienttest

server: 
  port: 8080
  context-path: /clienttest
  tomcat:
   uri-encoding: UTF-8

eureka:
 client:
   service-url:     {"defaultZone":"${service-url}"}
instance:
 prefer-ip-address: true

Please note the service-url value, now the value is set as {"defaultZone":"${service-url}"}, and in my application.properties file which on the config server, the properties file content is as below:

service-url=http://192.168.2.101:8769/eureka/,http://192.168.2.101:8770/eureka/

then when I start the mocroservice, it could resist it self on the http://192.168.2.101:8769/eureka/ and http://192.168.2.101:8770/eureka/

which is what result I want.

Gary Zhang
  • 33
  • 3
  • 6