Skip to content

Set environment variables for your application

Andreas Both edited this page Feb 14, 2023 · 1 revision

As the Qanary core components are implemented in Java using the Spring Boot framework and provided with a Docker configuration, the standard options for these technologies for changing runtime parameters (environment parameters, custom system settings) are also applicable here.

Setting environment variables for your Java process

While running your Qanary application directly via Java, provides you some standard Java mechanisms to easily set specific values for environment variables.

Change values in application.properties

You can change the existing values or add new environment variables in the file application.properties. After re-compiling your application, the new values are available. In the Qanary pipeline, the file is available in the folder src/main/resources/. In Qanary components, typically the equivalent files are stored in the folder src/main/resources/config.

More Information about the behavior of application.properties in Spring Boot is available here.

Add new variables in the application.local.properties

In our Qanary pipeline implementation, an additional file applications.local.properties is defined where you can define new values. The usage is the same as in the application.properties. However, the values in applications.local.properties are always overwriting possible existing values of the file application.properties.

Define environment variables in your console

As in any Java application, you can set environment variables on the shell, which will overwriting existing values. Let’s assume you want to set the log level of logging.level.org.springframework.web to ERROR. In this case, you need to set the environment variables using the uppcase-and-underscore format. For logging.level.org.springframework.web on a Linux OS it would be:

export LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=ERROR

Thereafter, start your application as usual.

Additional information can be found here.

Pass variables directly to your application

You can also pass variables directly to your application during the start of the Java JAR file. Let’s assume you want to set the log level of logging.level.org.springframework.web to ERROR. In this case, use the -D parameter. For example:

java -Dlogging.level.org.springframework.web=ERROR ...

More information is available here.

Setting environment variables for your Docker process

Running your Qanary system inside of Docker containers is very useful. Passing environment variables is very similar to your Docker containers can be done using the following methods.

Using the parameter -e (or an env file)

The following command would start a Docker container while passing a value to the Docker-internal system (same example as before).

docker run --env LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=ERROR ...

More details are available here.

You can also use an env file to collect all relevant value at once (cf. here).

Setting the values in docker-compose.yml

See the documentation.

Clone this wiki locally