'How to specify a profile in a Micronaut application?

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.



Solution 1:[1]

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

Solution 2:[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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 BazSTR