- Java: 11.0.7
- Micronaut: 2.1.2
- Micronaut profile: cli-app
I have an application developed with micronaut framework in cli-app profile. My application uses Hibernate and GORM packages, so there are relevant configurations in application.yml
In the default configuration, micronaut load application.yml from src/main/resources.
If I want my application load application.yml from the arguments like below:
java -Dmicronaut.config=/etc/fooApp/application.yml -jar fooApp.jar
How should I do ? Thanks
You can provide additional configuration files using
micronaut.config.filessystem property. You can define it either using-Dor by exporting theMICRONAUT_CONFIG_FILESenvironment variable.A variant with the
-Dsystem property optionA variant with the inlined environment variable
A variant with the exported environment variable
When you provide an additional configuration file with this technique, all values defined in the
/etc/fooApp/application.ymlwill take precedence over values defined in e.g.classpath:application.ymlfile. If you want to control a specific order, you will need to define comma-separated configuration files. For instance, if you want to provide an additional configuration file, but you want to take the precedence of theclasspath:application.ymlfile, then you need to do the following:More information: https://docs.micronaut.io/latest/guide/index.html#propertySource
⚠️ ATTENTION: If you want to hardcode this
/etc/fooApp.application.ymllocation to your CLI application, you can executein the
main()method of the CLI application class. However, you will getConfigurationExceptionif the file does not exist, so keep in mind that you might need to do some additional checks if you decide to go with this approach. I did something similar in thestackoverflow-cliapplication to store an access token and inject it later to the declarative HTTP client.