How to specify a profile in a Micronaut application?

Viewed 14610

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.

3 Answers

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

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

Related