Externalised configuration

Applications are typically built once (in JAR or WAR) and then deployed into multiple environments. ;The following figure shows some of the different environments an application can be deployed to:

In each of the preceding environments, an application typically ;has the following:

  • Connections to databases
  • Connections to multiple ;services
  • Specific environment configurations

It is a good practice to externalize configurations that change between different environments into a configuration file or database.

Spring Boot provides ;a flexible, standardized approach for externalized configuration.

In this section, we will look at the following:

  • How can properties from ;application.properties be used inside our services?
  • How do type-safe Configuration Properties ;make application configuration a cakewalk?
  • What kind of support does Spring Boot provide for Spring ;Profiles?
  • How can you configure properties in application.properties?

In Spring Boot, application.properties is the default file from which configuration values are picked up. Spring Boot can pick the ;application.properties file ;from anywhere on the classpath. ;Typically, application.properties is located at srcmain esources, as shown in the ;following screenshot:

In Chapter 6, Extending Microservices, we looked at examples of customizing Spring Security using configuration in application.properties:

    security.basic.enabled=false
management.security.enabled=false
security.user.name=user-name
security.user.password=user-password
security.oauth2.client.clientId: clientId
security.oauth2.client.clientSecret: clientSecret
security.oauth2.client.authorized-grant-types:
authorization_code,refresh_token,password
security.oauth2.client.scope: openid

Similar to these, all ;other Spring Boot starters, modules, and frameworks can be customized through configuration in ;application.properties. In the next section, let's look at some of the configuration options Spring Boot provides for these frameworks.

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

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