Search code examples
javaspringhibernate

How to load property file based on spring profiles


How to create project architecture to support multiple envionment. Each environment will have different datasource from different property file like(dev-propertfile,test-propertyFil,Production-propertyfile) with help of spring's

org.springframework.core.env.Environment;

Solution

  • I'll give step by step procedure for Spring boot applications.

    1. Inside /src/main/resources/application.properties mention spring.profiles.active=dev (or Prod)
    2. Create /src/main/resources/application-dev.properties and give your custom dev configurations here.
    3. Create /src/main/resources/application-prod.properties and give your custom prod configurations here.

    Run.