javaspring-bootapache-commons-config

Apache Commons Configuration set property to environment variable - how?


My SpringBoot project has the dependency

            <dependency>
              <groupId>org.apache.commons</groupId>
              <artifactId>commons-configuration2</artifactId>
              <version>2.4</version>
            </dependency>

And my bootstrap.properties file has lines such as aws.s3.name=${env:S3_NAME}

According to documentation on https://commons.apache.org/proper/commons-configuration/userguide/howto_basicfeatures.html, it is supposed to work with this syntax.

However when I try to use it:

    @Value("${aws.s3.name}")
    private String bucketName;

inside my @Service class, it is initialized to "S3_NAME".

Why? What am I doing wrong?

EDIT: I forgot to add that I am starting the application in a docker container, passing -e S3_NAME=some_bucket_name along with my docker run command


Solution

  • Turned out we were not using the correct tool (or correctly) - the right way was to move the environment variables properties from bootstrap.properties to application.properties - and then it started working!

    I dont know why there is difference in the way those two files function in Spring Boot.