Spring cloud composite bootstrap.yml - spring-boot

Is there any way how to "build" bootstrap.yml from multiple yaml files?
Here is my scenario, I have a bunch of micro-services and every service had the same bootstrap.yml properties expect spring.application.name.
I would like to split my bootstrap.yml into two files, base-bootstrap.yml which contains config service configuration like URI, password ... etc and then bootstrap.yml which could contain spring.application.name or whatever else.
base-bootstrap.yml file could be externalized in some dependency jar and should be used like default, bootstrap.yml should override any value. Here is some sample:
base-boostrap.yml
spring:
cloud:
config:
label: develop
uri: http://config
password: ${CONFIG_SERVICE_PASSWORD:password}
fail-fast: true
---
spring:
profiles: production
cloud:
config:
label: master
password: ${CONFIG_SERVICE_PASSWORD}
---
spring:
profiles: development
cloud:
config:
uri: http://localhost:8888
bootstrap.yml
spring:
application.name: sample-service
cloud:
config:
label: release/1.0.1
---
spring:
profiles: production
cloud:
config:
label: 1.1.0
Could anyone please guide me how to do it?

Related

Spring cloud config not apply global configuration

I'm having a problem on spring cloud configuration 2020.0.3, spring boot 2.4.5 for details:
Yaml configuration file is following Multi-profile YAML documents
I have a configuration yaml file on the config server.
my_cofig.yaml
spring:
datasource:
url: "jdbc:mariadb://localhost:3306/default_db"
driver-class-name: org.mariadb.jdbc.Driver
username: my_db
password: 12345
---
spring:
profiles: dev
datasource:
url: "jdbc:mariadb://localhost:3306/dev_db"
I have loaded the config from the config server by browser, it's correct.
But:
When I run Spring application with specific configuration (e.g. dev), Spring application must not apply global configuration variables defined on configuration file from configuration server. It only loads dev's configuration variables.
bootstrap.yaml
server:
port: 8081
spring:
application:
name: auth-service
cloud:
config:
enabled: true
fail-fast: true
allow-override: true
profile: dev
uri: http://localhost:5000
Error detail:
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Please help me, many thanks!
spring:
profiles:
This does not exist (it was deprecated if I am not mistaken). Please check the reference documentation.
I believe that what you are looking for is the following (reference documentation):
spring:
datasource:
url: "jdbc:mariadb://localhost:3306/default_db"
driver-class-name: org.mariadb.jdbc.Driver
username: my_db
password: 12345
---
spring:
config:
activate:
on-profile: dev
datasource:
url: "jdbc:mariadb://localhost:3306/dev_db"
Finaly, I solved the problem by upgrading spring boot version to 2.5.1
Thanks all

How to use application.propeties in spring cloud config client application?

How to use application.yml in spring cloud config client application?
spring:
application:
name: app-cli
profiles:
active: DEV
config:
import: "configserver:"
cloud:
config:
name: ${spring.application.name}
uri: http://192.168.0.12:8888
username: thirumal
password: thirumal
request-read-timeout: 200
request-connect-timeout: 100
fail-fast: true
The client app is configure with all the required properties, still it's not connecting to config-server.
The lib implementation 'org.springframework.cloud:spring-cloud-starter-config'

How can use ConfigDataEnvironmentPostProcessor and spring.profiles.group?

I'm using Spring Boot 2.4.2 and tried to use spring.profiles.group in my property files like:
application.yaml
spring:
profiles:
group:
local: core
application-core.yaml
---
spring:
config:
activate:
on-profile: local
...
but the "group" property is not found.
As I checked, it is using deprecated ConfigFileApplicationListener instead of ConfigDataEnvironmentPostProcessor.
Why it uses legacy spring profile processing even though version of spring is upper 2.4.0?
application-core.yaml doesn't require the following:
---
spring:
config:
activate:
on-profile: local
This is what is needed:
application.yaml:
spring:
profiles:
group:
local: core
application-core.yaml
...

Spring Cloud Config Server with Vault - vault overrides any value from native profile

I am trying to mix native and vault profile with config server backend:
spring:
profiles:
active: native, vault
cloud:
config:
server:
native:
searchLocations: classpath:/abc
vault:
kv-version: 2
when I start config server I curl for properties:
curl -X "GET" "http://localhost:20000/appName/dev" -H "X-Config-Token: xxxxxxxx"
I got empty propertySources list:
{"name":"appName","profiles":["dev"],"label":null,"version":null,"state":null,"propertySources":[]}%
but when I change my bootstrap file (remove vault profile):
spring:
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: classpath:/abc
vault:
kv-version: 2
It works: returning my properties:
{"name":"appName","profiles":["dev"],"label":null,"version":null,"state":null,"propertySources":[{"name":"classpath:/abc/appName-dev.yml","source":{"some.properties":"VALUE","....}
I did tried with "order" flags but still nothing...
The only workaround I found is bootstrap with "composite" profile like this:
spring:
profiles:
active: composite
cloud:
config:
server:
composite:
-
type: vault
kv-version: 2
-
type: native
searchLocations: classpath:/abc
But still don't know why it does not work with multi profile configuration, and why vault is overriding my native properties....

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.

Resources