Is it possible to add config locations without specifying spring.config.import in application.properties file?

Spring Boot adds default config locations in ConfigDataEnvironmentPostProcessor, e.g., classpath: and file:. I tried to do this in #1561, yet it has some problems:

  • I have to increase the order of GcpSecretManagerEnvironmentPostProcessor so that spring.config.import=sm:// can be added in the config location list by ConfigDataEnvironmentPostProcessor. However, other related properties, e.g., spring.cloud.gcp.secretmanager.allow-default-secret=true don't get parsed when initiating GcpSecretManagerProperties. I'm guessing ConfigDataEnvironmentPostProcessor gets called early so application.properties is not available yet.

  • spring-cloud-gcp-secretmanager dependency is required in the class path even if the user doesn't use it since resolving the config location sm:// always end up creating Secret Manager beans.

cc: @meltsufin

Comment From: philwebb

The spring.config.import property is pretty special, it's not designed to be used outside of the file that defines it. This is because you can have an import which itself then triggers another import.

I'm not sure exactly how your secrets management works so I can't offer any concrete advice. You might be able to change your GcpSecretManagerEnvironmentPostProcessor so that it has a constructor that accepts a ConfigurableBootstrapContext. If it was ordered after ConfigDataEnvironmentPostProcessor you could do logic similar to SecretManagerConfigDataLocationResolver to register things.