Spring Boot Profiles


In this tutorial, we will deep dive into the features that spring profile going to offer

Spring Profiles:

Spring profiles help you to conditionally select various beans and configuration that should be included into the project. This will be very helpful if you work with multiple environments and configurations.

Any @Component or @Configuration can be marked with @Profile. spring.profiles.active property is used to define your active profile. This can be mentioned either in the configuration file(application.properties or application.yml) or through program arguments. If an active profile is specified through program arguments it will replace the profile defined in configuration file. Sometimes it is useful to have profile-specific properties that add to the active profiles rather than replace them. The spring.profiles.include property can be used to unconditionally add active profiles.


You can also programmatically set your profiles using SpringApplication#setAdditionalProfiles().

Profile-specific variants of configurations can also be defined. For example for "development" profile application-development.properties file is read and for "production" profile application-production.properties file is read.

Find this project on Github

https://github.com/javacodenet/spring-boot-profiles/

pom.xml


Application.java


GenericConfiguration.java


ProdConfiguration.java


DevConfiguration.java


application.properties


application-production.properties


application-development.properties


Output


Comments

Popular posts from this blog

Generate Random values in Spring boot

Generate PDF From XML Or Java Object Using Apache FOP

Generate/Read an Excel file in Java using Apache POI