From the course: Extending, Securing, and Dockerizing Spring Boot Microservices

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Selecting Spring profiles at runtime

Selecting Spring profiles at runtime

From the course: Extending, Securing, and Dockerizing Spring Boot Microservices

Start my 1-month free trial

Selecting Spring profiles at runtime

- [Instructor] Spring profiles provide a way to segregate parts of your application configuration and make it available to only certain environments. We will learn how to define Spring profiles with properties files and enable them at runtime. So, I'd like to have a profile that uses H2 in memory database and another that interacts with MySQL. To do this with properties files, I created another file called application-mysql.properties in the resources folder, so this would be the profile called MySQL. And it contains the settings that are just for interacting with the MySQL database container. Back in application.properties, we need to set an active profile and so, the spring.profiles.active set to default means that whenever the application starts up, only these properties will be set. So, that is set at runtime either as a JVM parameter, an operating system environment or even a cloud configuration in a server or this way we have it just in the application.properties file. So…

Contents