salesforce / rules_spring

Bazel rule for building Spring Boot apps as a deployable jar
BSD 3-Clause "New" or "Revised" License
224 stars 48 forks source link

Support externalized configuration for launching with bazel run #135

Open plaird opened 3 years ago

plaird commented 3 years ago

It is a useful feature for Spring Boot to load external configuration files (files not included in the exectuable jar) at runtime. This allows you to override some properties in production for example. You can do this via command line arguments, but the property file approach is common.

https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.files

Spring Boot will automatically find and load application.properties and application.yaml files from the following locations when your application starts:

  • The current directory
  • The /config subdirectory in the current directory
  • Immediate child directories of the /config subdirectory

This works if you launch the rules_spring built executable jar with java -jar:

java -jar example.jar

But we don't have a great way to do this when launching the application with bazel run. As a workaround the developer can invoke bazel run like this:

bazel run //examples/demoapp -- --spring.config.location=/tmp/demoapp/config/

but it feels like we should automatically honor package level files like:

When working on this, remember to support profile specific prop files: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.files.profile-specific