Member-only story
Complex Spring Placeholder Resolution
I had a complicated case for Spring Boot properties configuration today that I’d like to share.
My project uses Atomikos for XA transaction management. Atomikos needs to store its transaction logs somewhere, and there’s a special Spring Boot property spring.jta.log-dir
that configures the directory to use for these logs. The property is configured in the application.yml
file.
The transaction logs that are generated during tests may be safely deleted after the tests have passed, so it makes sense to dump these logs under the target
directory of the Maven module. Then they will not pollute the source code and will be naturally disposed of during Maven’s clean
.
However, there are two different cases for running those tests —from IDEA (manually) and from Maven (as part of the automated Jenkins build). I needed to make sure that in both cases the logs end up under the target
directory.
Whenever I run my application using a Spring Boot run configuration in IntelliJ IDEA, I want those logs to end up in a special pre-configured directory under my user’s home folder. When I run the application as part of the Docker container (production environment), I want them to end up in a folder provided in a specific environment variable (it should point to an external Docker-mounted volume).