8.1 Cloud Configuration
Applications that are built for the Cloud often need adapt to running in a Cloud environment, read and share configuration in a distributed manner and externalize configuration to the environment where necessary.
Micronaut’s Environment concept is by default Cloud platform aware and will make a best effort to detect the underlying active environment.
You can then use the Requires annotation to conditionally load bean definitions.
The following table summarizes the constants provided by the Environment interface and provides an example:
Constant | Description | Requires Example | Environment name |
---|---|---|---|
The application is running as an Android application |
|
| |
The application is running within a JUnit or Spock test |
|
| |
The application is running in a Cloud environment (present for all other cloud platform types) |
|
| |
Running on Amazon EC2 |
|
| |
Running on Google Compute |
|
| |
Running on Kubernetes |
|
| |
Running on Heroku |
|
| |
Running on Cloud Foundry |
|
| |
Running on Microsoft Azure |
|
| |
Running on IBM Cloud |
|
| |
Running on Digital Ocean |
|
| |
Running on Oracle Cloud |
|
|
Note that it may be the case that you have multiple active environment names since you may run Kubernetes on AWS for example.
In addition, using the value of the constants defined in the table above you can create environment specific configuration files. For example if you create a src/main/resources/application-gcp.yml
file then that configuration will only be loaded when running on Google Compute.
Any configuration property in the Environment can also be set via an environment variable. For example, setting the CONSUL_CLIENT_HOST environment variable will override the host property in ConsulConfiguration. |