Selecting profiles

Before running an application supporting different profiles, you will need to select the desired profile to use the configuration needed. A profile can be selected using the spring.profiles.active flag using the JVM parameter, as follows:

$ java -Dspring.profiles.active=dev -jar target/infra-as-code-0.0.1-SNAPSHOT.jar

Finally, you can check the application in the browser using the port associated with the profile provided. Valid values for the spring.profiles.active flag are as follows:

  • dev
  • production
  • test

If you don't provide any value for the flag, then the configurations from application.properties will be used.

This is a simple example of exploring profiles in Spring. Remember that with profiles, we can also configure datasources, queues, beans, and anything you need. You can always override any of the provided configuration variables using environment variables.

Additionally, as we saw in Chapter 10, Containerizing Your Applications, we are able to dockerize a Spring Boot application, and with this knowledge, we can learn about immutable servers and how to test infrastructure changes. 

In this section, we are going to learn a similar way to recreate the infrastructure using Vagrant (https://www.vagrantup.com/) version 1.7.0 or later. This may require virtualization software (for example, VirtualBox: https://www.virtualbox.org/).

Another tool that can perform the same task is Ansible (http://ansible.com/), which is not covered in this chapter.
..................Content has been hidden....................

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