/
Environment-Specific Application Properties Guideline

Environment-Specific Application Properties Guideline

Introduction

In modern software development, effectively managing different configurations for various environments—such as development, testing, staging, and production—is crucial. This guideline outlines best practices for managing environment-specific application properties files in your project.

Do’s

Structure and Naming Conventions

  1. Base Configuration: Create a default application.properties file containing properties common to all environments.

    • Path: src/main/resources/application.properties

  2. Environment-Specific Configuration: Create separate properties files for each environment, following the naming convention application-{environment}.properties. For example:

    • src/main/resources/application-dev.properties

    • src/main/resources/application-test.properties

    • src/main/resources/application-prod.properties

  3. Profile Activation: Activate the environment-specific profile through the command line, environment variables, or the main application configuration.

    • Using CLI:

      java -jar myapp.jar --spring.profiles.active=dev
    • Using Base application.properties:
      Add the following property to the base property file:

      spring.profiles.active=prod

Don’ts

  • Do not add the same property with different environment values in the same properties file. For example, avoid having url.staging and url.prod in the same file.

  • Do not create different variables for the same property with different environment values. For instance, avoid using String urlStaging and String urlProd .

Related content