Disabling Environment Detection
The automatic detection of environments can be disabled setting the micronaut.env.deduction
system property or the MICRONAUT_ENV_DEDUCTION
environment variable to false
. This will prevent Micronaut from detecting current environments, while still using any environments that are specifically provided as shown above.
Disabling environment detection via system property
$ java -Dmicronaut.env.deduction=false -jar myapp.jar
Alternatively, you can disable environment deduction using the ApplicationContextBuilder‘s deduceEnvironment
method when setting up your application.
Using ApplicationContextBuilder to disable environment deduction
@Test
public void testDisableEnvironmentDeductionViaBuilder() {
ApplicationContext ctx = ApplicationContext.builder().deduceEnvironment(false).start();
assertFalse(ctx.getEnvironment().getActiveNames().contains(Environment.TEST));
ctx.close();
}
Using ApplicationContextBuilder to disable environment deduction
void "test disable environment deduction via builder"() {
when:
ApplicationContext ctx = ApplicationContext.builder().deduceEnvironment(false).start()
then:
!ctx.environment.activeNames.contains(Environment.TEST)
cleanup:
ctx.close()
}
Using ApplicationContextBuilder to disable environment deduction
"test disable environment deduction via builder"() {
val ctx = ApplicationContext.builder().deduceEnvironment(false).start()
assertFalse(ctx.environment.activeNames.contains(Environment.TEST))
ctx.close()
}