Spring Profile

When we deploy our application to the server, we will need to use a different set of configurations, such as the database's username, password, and URL, and so on. Spring Profiles provides a way to segregate the configuration for different environments.

We have the following environments for this:

  • dev: The local development environment
  • test: The unit test environment
  • e2e: The end-to-end test environment
  • staging: The staging environment
  • production: The production environment

With Spring Profile, we can create a profile-specific configuration file, for example, the application-dev.properties file that we created for the local development environment, and, we use application.properties as the base configuration. Other configurations will override the defaults in the base configuration. For example, in our application.properties, we use <username> and <password> for the database connection:

spring.datasource.username=<username>
spring.datasource.password=<password>

In application-dev.properties, we override these two configurations with the actual username and password in the local development environment. We will do the same for other environments, especially, the staging and the production environment.

Now, let's take a look at each environment profile.

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

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