简体   繁体   中英

Add a file to spring properties

I would like to add a file to a spring properties YAML file. What would be the best way to do it? I'm providing default files, but the user has to be able to change them and add his files as well. These files are mainly certificates and keystores.

My solution to this problem is to encode a file in base64 and then store this string as a property to load at the runtime. But i wonder if there is a better way to store these files? For example:

trustedProfileKeystoreFile: MIIJcgIBA(..)zCCCTwGCSqGS

But i need a way to store multiple files also:

trustedCertificateFiles:
      - Q2VydGl(..)maWNhdG
      - RQTF4zr4(..)fzaw512

However Spring does not allow to store a list of strings like in the example above and i would have to "hack" it like in the post in patrickjamesbarry comment . I cannot store all files in a single folder and then load this folder because the application will be available at docker and that would mean that i have to mount multiple folders for multiple types of files, and that's not acceptable. I need to have a centralized way to save all files.

yml file is the configuration file, and you cannot overload it with something which has no relation to it. you should rather put the file locations in YAML file, and extract data in code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM