Search code examples
javaspringdependency-injectionspring-bootproperties-file

spring-boot: configuring different versions of a property-file with hardcoded filename?


Building a spring-boot app, we are depending on a 3rd party jar-file, that expects to find a properties-file with hardcoded filename (say xyz.properties) on the classpath, and will read its properties from that.

We need, though, to "switch in" different version of this properties-file, depending on in which environment we deploy the jar-file. So would need, preferably, to add to the classpath a directory external to the jar-file, where we can put the properties-file.

Googling this, I find other people having similar issue, but not a simple, clean solution for it. It seems to me, the spring properties-model assumes you only care abt the property-names and their values (picking them up from System.getProperties()) and really dont care abt from which property-file each value comes.

This may be fine when building your own code along that model, but may fit not so well when depending on 3rd party solutions, like our use-case.

The simplest workaround I found is to "explode" the spring jar file, then copy desired property-files into WEB-INF/classes, then start with the JarLauncher.

Just wondering if there is a better way, without need to "explode" it?

Is my understanding above correct, or have I just overlooked some spring-feature that already supports this use-case?


Solution

  • Hopefully it still works - but with some trick you can set your own classpath:

    java -cp "./conf/:yourBoot.jar" org.springframework.boot.loader.JarLauncher
    

    and then you can place your config in external dir (as you already suggested).

    See original question: Add jar file to spring-boot classpath at runtime