How to load property file based on spring profiles

2022-09-03 00:19:28

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;

答案 1

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.


答案 2

Put property file in same location as and follow the naming convention like ,, application.propertyapplication-{profile}.propertiesapplication-dev.propertiesapplication-test.propertiesapplication-prod.properties

And in set etcapplication.propertiesspring.profiles.active=dev,test


推荐