1

I'm running my Spring Boot application with Kubernetes. Part of the architecture involves mounting secrets as file volumes under /opt/config.

$ ls -l
SECRET_1
SECRET_2
SECRET_3

Each file contains a .properties like syntax. (key=value)

I've been attemtping to make Spring Boot load these as per the documentation spring.config.import=file:/etc/config/myconfig[.yaml]

However I just can't get this to work, my full command is: java -Dspring.config.location=file:./opt/application.properties -Dspring.config.additional-location=file:./opt/config/*[.properties] -jar target/test.war --debug --server.port=8080

The ./opt/application.properties file is loaded correctly.

I have also attempted to rename all the files to include .properties:

$ ls -l
SECRET_1.properties
SECRET_2.properties
SECRET_3.properties

And load it via java -Dspring.config.location=file:./opt/application.properties -Dspring.config.import=file:./opt/config/*/ -jar target/test.war --debug --server.port=8080, however this also did not import any of the properties under ./opt/config.

I've read through the documentation dozens of times now, and this should be working, but it's not. Did I miss something obvious? Why is it not loading any of the files under ./opt/config?

liquid5109
  • 105
  • 11

1 Answers1

0

I think the problem is that the locations you specify are where spring looks for application.properties, application.yml and profile variants (application-prod.properties, etc). I think you are better off loading all the files in a configured location programmatically, this might provide some ideas.

Hopey One
  • 1,681
  • 5
  • 10
  • I don't really understand your answer. I'm looking for a way to import properties from generated files. I know how to access properties, I just can't seem to make Spring Boot import them. – liquid5109 Nov 23 '20 at 06:58
  • I don't think the `spring.config.import` option property works the way you think it does. You could import each file individually as per `spring.config.import=file:/etc/config/SECRET_1[.properties]` from in the application.properties. I can't see however anything in the documentation that says you can wildcard the import or use `spring.config.import` on the command line. – Hopey One Nov 23 '20 at 11:35
  • You're right, the wildcard seems only related to `spring.config.location`. I guess I'll need to explicitly list all names for import. – liquid5109 Nov 24 '20 at 06:23