Profiles

Applications usually need different settings during development and in tests, such as a local database, more detailed logging, or test-only beans. Spring Boot supports that with profiles, but you have to activate the right profile in every place you launch the application from:

  • the IntelliJ IDEA run configuration, which has its own setting for the active profiles and doesn’t use the ones configured in your Gradle or Maven build;

  • the Gradle build, once for the bootRun task and once for the test task, or the Maven build, in the Spring Boot Maven Plugin and in the Surefire Plugin;

  • the VS Code launch configuration, and its separate configuration for running tests;

  • the tests, for example with @ActiveProfiles("test") on each test class.

Each of these places is easy to forget, differs between team members, and has to be repeated in every project.

Arconia activates the profile for you, based on the bootstrap mode:

  • dev when the application runs in dev mode;

  • test when it runs in test mode.

You only need to put your settings in application-dev.yml and application-test.yml. They apply wherever you run the application or its tests, from any IDE or build tool, with no further configuration. In prod mode, no profile is activated.

src/main/resources/application-dev.yml
logging:
  level:
    com.example: debug

The profiles activated by Arconia come before the ones you activate yourself, for example with spring.profiles.active, so your own profile-specific configuration files still take precedence.

How Profiles Are Activated

Arconia activates the mode-specific profiles right before Spring Boot loads the application configuration. As a result, profile-specific configuration files (such as application-dev.yml) are loaded as part of the standard Spring Boot configuration flow, including when configuration is imported from external sources (such as Spring Cloud Config Server or HashiCorp Vault via spring.config.import).

The mode-specific profiles become active profiles, so, as in Spring Boot, the default profiles (spring.profiles.default) no longer apply. If you rely on them, add them to arconia.dev.profiles and arconia.test.profiles, or disable the automatic activation.

Customizing the Profiles

You can choose which profiles each mode activates. For example, your team may use a local profile instead of dev for the configuration to use during development.

Since the profiles must be activated before the application configuration is loaded, the profile settings cannot be defined in regular application configuration files like application.yml. They are supported in the following locations, in decreasing order of precedence:

  • command line arguments (e.g. --arconia.dev.profiles=local);

  • JVM system properties (e.g. -Darconia.dev.profiles=local);

  • environment variables (e.g. ARCONIA_DEV_PROFILES=local);

  • the META-INF/arconia-bootstrap.properties file.

If any of these properties is found in the application configuration, Arconia logs a warning at startup, since the value would otherwise be silently ignored.

The Bootstrap Configuration File

For team conventions that should be checked in with the application, you can create a META-INF/arconia-bootstrap.properties file in your classpath (e.g. src/main/resources/META-INF/arconia-bootstrap.properties):

arconia.dev.profiles=local
arconia.test.profiles=integration

The file uses the Java Properties format and supports only the profile settings listed on this page. It’s read before the application configuration is loaded, so there are no profile-specific variants of it. When multiple files are present, the first one found on the classpath is used: for example, a file in src/test/resources takes precedence over the one in src/main/resources when running tests. The bootstrap mode itself cannot be set in this file, since the file is checked in with the application, whereas the mode describes how the application is launched.

Disabling the Automatic Activation

You can disable the automatic activation of the profiles via the arconia.bootstrap.profiles.enabled property, for example in the bootstrap configuration file:

arconia.bootstrap.profiles.enabled=false

Configuration Properties

Table 1. Profiles Configuration Properties
Property Default Description

arconia.bootstrap.profiles.enabled

true

Whether the profiles are enabled based on the application mode.

arconia.dev.profiles

dev

Names of the profiles to activate in dev mode.

arconia.test.profiles

test

Names of the profiles to activate in test mode.

Both profile properties accept a list of profiles. For example, you can define multiple profiles to be activated when running in dev mode:

arconia.dev.profiles=dev,local