What are spring profiles?
Spring applications typically have a large set of such configurations that vary across environments. In such scenarios, you can use Spring profiles. Spring profiles provide a way to segregate parts of your application configuration and make it be available only in certain environments. In this post, we will learn how to use Spring profile.
How do I set up a profile programmatically in Spring Boot?
The initialization parameter spring.profiles.active, introduced in Section 4, can also be set up as a property in Spring Boot to define currently active profiles. This is a standard property that Spring Boot will pick up automatically: spring.profiles.active=dev. To set profiles programmatically, we can also use the SpringApplication class:
What are the DataSource related properties in Spring Boot?
These are simple datasource related properties. The default properties has common things like driver and database username. Moreover, Spring Boot reads the default properties file in all profiles. The other two files contains environment specific properties, such as database url and database password.
How to target different environments in Spring Boot?
If we need to target different environments, there’s a built-in mechanism for that in Boot. We can simply define an application-environment.properties file in the src/main/resources directory, and then set a Spring profile with the same environment name.