YAML configuration

Spring Boot also supports YAML to configure your properties.

YAML is an abbreviation for "YAML Ain't Markup Language". It is a human readable structured format. YAML is commonly used for configuration files.

To understand basic syntax of YAML, look at the example below ;(application.yaml). This shows how our application configuration can be specified in YAML.

spring:
profiles:
active: prod
security:
basic:
enabled: false
user:
name=user-name
password=user-password
oauth2:
client:
clientId: clientId
clientSecret: clientSecret
authorized-grant-types: authorization_code,refresh_token,password
scope: openid
application:
enableSwitchForService1: true
service1Url: http://abc-dev.service.com/somethingelse
service1Timeout: 250

As you can see, the YAML configuration is much more readable than application.properties, as it allows better grouping of properties.

Another advantage of YAML is that it allows you to specify the configuration for multiple profiles in a single configuration file. The following snippet shows an example:

application:
service1Url: http://service.default.com
---
spring:
profiles: dev
application:
service1Url: http://service.dev.com
---
spring:
profiles: prod
application:
service1Url: http://service.prod.com

In this example, ;http://service.dev.com will be used in the dev profile, and ;http://service.prod.com is used in the prod profile. In all other profiles, http://service.default.com will be used as the service URL.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset