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

  1. $ 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

  1. @Test
  2. public void testDisableEnvironmentDeductionViaBuilder() {
  3. ApplicationContext ctx = ApplicationContext.builder().deduceEnvironment(false).start();
  4. assertFalse(ctx.getEnvironment().getActiveNames().contains(Environment.TEST));
  5. ctx.close();
  6. }

Using ApplicationContextBuilder to disable environment deduction

  1. void "test disable environment deduction via builder"() {
  2. when:
  3. ApplicationContext ctx = ApplicationContext.builder().deduceEnvironment(false).start()
  4. then:
  5. !ctx.environment.activeNames.contains(Environment.TEST)
  6. cleanup:
  7. ctx.close()
  8. }

Using ApplicationContextBuilder to disable environment deduction

  1. "test disable environment deduction via builder"() {
  2. val ctx = ApplicationContext.builder().deduceEnvironment(false).start()
  3. assertFalse(ctx.environment.activeNames.contains(Environment.TEST))
  4. ctx.close()
  5. }