Supporting different environments

A common scenario in the delivery of an application is that we code the application on a development environment (almost always our own computer) and then the application is deployed in different test and production environments. Spring configuration files allow us to use different configurations on each environment. We can use a local configuration file as part of an application and then later, we can override those configuration values using environment variables. This is commonly needed because we use different credentials and configurations for each environment of our deployment configuration.

Before creating different Spring configuration files for each of the different environments that we need to deploy our application on, we are going to add an index.html static page behind the /main/resources/static folder with the following label:

<!DOCTYPE html>
<
html lang="en">
<
head>
<
meta charset="UTF-8">
<
title>Welcome devops</title>
</
head>

For the next steps, we are going to show some features that Spring offers in favor of DevOps. We are also going to complete an exercise in which we provide Docker containers with layers that will be configured to support different environments, such as development, testing, and production environments. 

First, we are going to create a different profile for our application. For example, we can create different configuration files for development, testing, and production, using three files named application-dev.properties, application-test.properties and application-production.properties in the /infra-as-code/src/main/resources folder:

In order to see how Spring Profiles work, we are going to change the port that our application is using. The property that is used to configure the port is server.port. Let's change this value for each one of the different files we have, as follows: 

application-dev.properties:

server.port = 8090

application-test.properties:

server.port = 8091

application-production.properties:

server.port = 8092
..................Content has been hidden....................

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