2

I'm working currently on a Spring boot project, and we have an application.properties file that defines a path where we have 2 jks files. (the original file has more key/value pairs, but I'm focusing in the main problem with these two pairs)

example

file1.example=folder/file1.jks
file12.example=folder/file2.jks

But now, I need to read an environment variable that contains an encoded value that I need to take, decode and use to create these files. The main problem is that I need to create these two files before the properties are "loaded" because these files do not exist, if I first don't build them, any idea?

  • This something like this help? https://stackoverflow.com/questions/65859403/how-to-add-external-jars-to-spring-application-without-restarting-jvm – knittl May 20 '22 at 23:08

1 Answers1

3

Normally Spring boot launches from the following main method. You can define a static method before the launcher is called so that in that method you use whatever environment variable you want and make I/O operations to prepare the files. Then if this is done successfully you can let Spring Boot start the server and application normally.

@SpringBootApplication
public class ConfigurationApplication {

    public static void main(String[] args) {
        createPropertiesFiles();   <---------------
        SpringApplication.run(ConfigurationApplication.class, args);
     }

    private static void createPropertiesFiles(){
        // I/O operations to create those files ...
    }

 }
Panagiotis Bougioukos
  • 15,955
  • 2
  • 30
  • 47