Bootstrap Mode
Arconia detects whether your Spring Boot application is running during development, in tests, or in production, and adapts its behavior to that context. You don’t need to configure anything: running the application from your IDE or build tool, running tests, and running the packaged application are recognized automatically.
The bootstrap mode is the single switch that every Arconia feature relies on:
-
devwhen you run the application during development, for example from your IDE or with./gradlew bootRun. Arconia activates thedevprofile and starts the Dev Services your application needs, keeping their containers across Spring Boot DevTools restarts. -
testwhen you run tests. Arconia activates thetestprofile and starts the Dev Services your tests need. -
prodin all other cases, including the packaged application. No development or test feature is active, so nothing meant for your machine ends up running in production.
Learn more about the profiles activated in each mode in Profiles, and about the services started for you in Dev Services.
Setting the Bootstrap Mode
Usually, you don’t need to set the bootstrap mode, since Arconia determines it as described in the next section. If your setup isn’t recognized, set it explicitly with the arconia.bootstrap.mode JVM system property (-Darconia.bootstrap.mode=dev) or the ARCONIA_BOOTSTRAP_MODE environment variable. If both are set, the JVM system property takes precedence, as in the Spring Boot externalized configuration. When you use the Arconia CLI, it sets the bootstrap mode for you when running (arconia dev) or testing (arconia test) your application.
The bootstrap mode describes how the application is launched, so it’s read before the application configuration. Setting it anywhere else, such as in application.yml, in the META-INF/arconia-bootstrap.properties file, or as a command line argument, has no effect, and Arconia logs a warning.
|
How the Bootstrap Mode Is Determined
When the bootstrap mode is not set explicitly, Arconia determines it using the following heuristics, in order:
-
prodwhen the application is being processed ahead-of-time (Spring AOT), so that the production behavior is baked into the AOT artifacts. -
testwhen a test framework (JUnit, TestNG, Cucumber, Spring Boot Test) is found in the call stack. -
prodwhen the application is running as a GraalVM native image. -
devwhen Spring Boot DevTools is on the classpath, or when the application is running from the output directories of a build tool or IDE (Gradle, Maven, IntelliJ IDEA, Eclipse), which only happens at development time. -
prodin all other cases, including packaged applications (JAR, exploded classpath, container image).
If the heuristics don’t recognize your setup (for example, a custom launcher or build tool), the application runs in prod mode, which is the safest default. In that case, you can set the bootstrap mode explicitly.
Checking the Active Bootstrap Mode
When running in dev or test mode, Arconia logs the active mode at startup:
The application is running in dev mode
To check the mode in your code, use BootstrapMode.detect(), or the BootstrapMode.isDev() and BootstrapMode.isTest() shortcuts, from the io.arconia.core.bootstrap package. The mode is detected once and cached for the lifetime of the JVM.
Registering Beans Based on the Bootstrap Mode
You can register beans conditionally based on the bootstrap mode using the @ConditionalOnDevMode annotation, which only matches when the application is running in dev mode. It can be applied to @Bean methods as well as to @Configuration and auto-configuration classes, both in applications and in libraries building on top of Arconia.
@Configuration(proxyBeanMethods = false)
public class GreetingConfiguration {
@Bean
@ConditionalOnDevMode
GreetingService devGreetingService() {
return new LocalGreetingService();
}
}
| During Spring AOT processing and in GraalVM native images, the application runs in prod mode, so the condition doesn’t match and the beans are excluded from the AOT artifacts. |