Profiles in Spring Boot

Posted By :Rozi Ali |30th November 2020

Spring Boot Profiles


A profile can be describe as a set of properties and configuartion settings. An application can have multiple profiles which we may use to execute in different environments, like Dev, Stage, Production. Also, we can have different databases for different profile for a particular application.

In Spring Boot, we create a different properties file for every new profile. We can control the active state of these profiles in file, which is the master properties file.

Note: If more than one profile is specified, then the last one will gain precedence.


Also Read: Spring Boot Data Rest


Steps to create a profile in Spring Boot


Step 1


Create a properties file for a profile: Define file name as - application-{profile}.properties




Step 2


Specify profile in file 

Here, in property, we mention the profile name that we want to active


Step 3 


Next step is to configure database in

@Profile annotation is used to set a bean to a defined profile 

public class DBConfiguration{
    private String driverClassName;
    private String url;
    private String username;
    private String password;

    public String devDatabaseConnection(){
          return "Dev database connection";

Note: If we user @Profile annotation as @Profile(!Dev) then this specify that this bean does not belong to Dev. And if a bean does not specify a profile then it belongs to a default bean.


Also Read: Spring Boot Application Configured As Eureka Server


That's it! This is is how you create a profile and set it's status active.


Why You Should Choose Oodles For SaaS Product Development?


We are a 360-degree software development company that provides cross-platform SaaS app development services to address varied software project requirements. We have an experienced team of Java, PHP, and Python developers who use advanced frameworks, tools, and SDKs to build scalable web and mobile applications with custom features. For more detail, reach us out at [email protected].

About Author

Rozi Ali

She is self-motivated and dedicated person in Development team. She is working on Java Technology.

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us