How to read multiple yml config files from spring cloud config server - spring

I have seen that spring config server will read ${spring.application.name}.yml. I have two files in my config server namely, test.yml and test-dev.yml. While i am running the config client, it is only picking either of the files. I want it to pick both the files at the same time.
Thanks!

This config goes into your client app:
spring:
application:
name: <AppName>
cloud:
config:
uri: <ConfigUrl>
enabled: true
fail-fast: true
name: test,test-dev

Related

Spring cloud config server setting for logging are never picked up

I have a spring cloud config client and server. I have added some logging-logback settings in the application.yaml of client and I have a different setting under config server. I see that the settings from server are never picked. Can somebody please help. I tried with different versions of spring boot and cloud but observe the same behaviour everywhere.
Please note, I only have issues with the logback.rollingpolicy.max-file-size
All other properties are picked from config-server
My application.yaml in the client
logging:
level:
root: info
file:
path: /Users/abc/demo/src/main/resources/logs
name: application
logback:
rollingpolicy:
max-file-size: 1MB
My bootstrap.yaml
spring:
cloud:
config:
enabled: true
uri: http://localhost:8402
application:
name: demo
My demo.yaml in cloud config server
logging:
level:
root: info
file:
path: /Users/abc/demo/src/main/resources/logs
name: demo
logback:
rollingpolicy:
max-file-size: 500KB

How to access multiple application yml from difference service on configure server(Spring)

I have configured "configure-server" by fetching all configuration from gitlab repository.
Currently, when application(config-server) start it fetch all application properties in git repo.
In case, I have two client application A,B
which has difference application properties like
aplication-a.yml
aplication-b.yml
when application A start, I just only want configure-service fetch only application-a.yml from git repositry.
Here is application configure:
Configure Server
server:
port: 9000
spring:
application:
name: CONFIG-SERVER
cloud:
config:
server:
git:
uri: https://gitlab.com/mama/cloud-configure-server.git
clone-on-start: true
default-label: main
Application A
spring:
cloud:
config:
enabled: true
uri: http://localhost:9000
How to tell configure-service fetch only application-a.yml from git repository?
In case, I don't want to fetch all?
Thank you!!

When spring config server is down and GIT under maintenance and spring config client at the initial startup

Spring Config-Client is in initial startup so It would not have cached the data from config server,
if either Config-Server or GIT or both are down - what can be done in that case to get the data and maintain service availability.
You can use the following (basedir) element of yml file with following hierarchy.
The "basedir" element will cache your config data whenever application restarts and keep that on the specified path which is specified against this key as a value.
Example :
basedir : C:\POC_CONFIG_SERVER\config-repo-am
server:
port: 8888
spring:
application:
name: cloud-config-server
cloud:
config:
server:
git:
uri: ${uri}
force-pull: true
skip-ssl-validation: true
skipSslValidation: true
username: ${username}
password: '${password}'
default-label: master
basedir: ${basedir}

how to make spring boot client's application.yml get value from config server

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

spring cloud config versioning

I have all the common properties in application.properties file. version specific properties are in version1 and version2 folders in github.
order-service(base folder)
application.properties
version1
app-dev.properties
version2
app-dev.properties
How can I set the config in application.yml file to ensure cloud config server returns version 1 props along with with common props when version1 url is hit.Below is the config that I have now to fetch props from base folder and how could it be modified to achieve the above.
spring:
cloud:
config:
server:
git:
uri: https://github.company.com/orders-properties
username: orders
password: orders
search-paths: order-service
If I understood correctly this is what you need.
Lets say you have two apps called app-dev-v1 and app-dev-v2.
You need to add a bootstrap.yml file inside the resources folder and add this property on both the apps.
For app-dev-v1
spring:
application:
name: app-dev-v1
For app-dev-v2
spring:
application:
name: app-dev-v2
In the repository you can have a .yml or .properties file like this inside version1 and version2 folder.
app-dev-v1.yml and app-dev-v2.yml
Also for config server you need to add the search paths:
spring:
cloud:
config:
server:
git:
uri: https://github.company.com/orders-properties
username: orders
password: orders
search-paths: order-service,version*

Resources