14

I want to specify different types of configs depending on the environment that I will deploy the app. Like in Spring-boot in the yml file we can set the profile, I want to know if there is a way to do it in Micronaut.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
tomas lingotti
  • 171
  • 1
  • 1
  • 7

3 Answers3

16

You can set active environment(s) either by system property micronaut.environments (java -Dmicronaut.environments=foo,bar -jar myapp.jar) or by environment variable MICRONAUT_ENVIRONMENTS.

See Documentation: https://docs.micronaut.io/snapshot/guide/index.html#environments

Sascha Frinken
  • 3,134
  • 1
  • 24
  • 27
2

Here is my example of how to build and run Micronaut using environment variables and CMD in Win 10 with prod profile:

gradlew clean build -x test -x integrationTest
set MICRONAUT_ENVIRONMENTS=prod
echo %MICRONAUT_ENVIRONMENTS%
java -jar build/libs/app.jar 

Don't forget to check the environment in the console log after starting. Search for: "Environment(s): [prod]".

Solution with system property (java -Dmicronaut.environments=foo,bar -jar myapp.jar) does not work for me, but under Ubuntu/Mac it works fine. I'm using micronautVersion=2.4.4

BazSTR
  • 129
  • 3
1

If you are trying to do this with gradle and the run task, you can take the following approach.

build.gradle

run {
    systemProperties([
        'micronaut.environments': 'local'
    ])
}

This by default will read from application.yaml and application-local.yaml

fieldju
  • 1,443
  • 1
  • 14
  • 20