Spring Profiles and Property File Locations
Self-managed Micro-Integrations use Spring Boot for configuration, allowing you to:
-
use Spring profiles to manage environment-specific configurations
-
provide settings as property files or environment variables
For information about how the Micro-Integration detects configuration properties, see Externalized Configuration in the Spring Boot documentation.
For information about converting Spring property names to environment variables, see Binding From Environment Variables in the Spring Boot documentation.
Spring Profiles
If multiple configuration files exist within the same configuration directory for use in different environments (development, production, and so on), use Spring profiles.
Using Spring profiles allows you to define different application property files under the same directory using the application-{profile}.yml filename format.
For example:
-
application.yml: The properties in non-specific files that always apply. Its properties are overridden by the properties defined in profile-specific files. -
application-dev.yml: Defines properties specific to the development environment. -
application-prod.yml: Defines properties specific to the production environment.
Individual profiles can then be enabled by setting the spring.profiles.active property. For more information and an example, see Spring Boot: Profile-Specific Files.
Configuring Locations to Find Spring Property Files
By default, the Micro-Integration detects any Spring property files that are located in Spring Boot's default locations.
-
If you want to configure additional locations, add
--spring.config.additional-location=file:<custom-config-dir>. -
If you want to exclusively use the locations that you've defined and ignore Spring Boot's default locations, add
--spring.config.location=optional:classpath:/,optional:classpath:/config/,file:<custom-config-dir>.
For an example of the command to configure additional locations, see Quick Start: Running a Self-Managed Micro-Integration From the Command Line.
For more information about configuring locations to find Spring property files, see Spring Boot documentation.
If you want configuration files for multiple different Micro-Integrations within the same config directory for use in different environments (such as development, production, etc.), we recommend that you use Spring Boot Profiles instead of child directories.
For example, set up your configuration like this:
config/application-prod.ymlconfig/application-dev.yml
Do not set it up like this:
config/prod/application.ymlconfig/dev/application.yml
Child directories are intended to be used for merging configuration from multiple sources of configuration properties. For more information about when to use child directories, see the Spring Boot documentation.