Search code examples
javaspring-cloudspring-cloud-streamspring-cloud-config

Spring cloud config - Share file or his location


I have two applications :

  • one spriig boot config server
  • the another one a spring boot config client

The client side have to use a file named certificate.json.

I want to store this file in the server side so another microprogram and my client programm who need it can retrieve it from the server side.

I try that :

  • copy the file certificate.json to classpath:/config
  • add this line to the application.properties :

    certificate.location: classpath:config/certificate.json

  • call the value from client programm by :

    @Value("${certificate.location}") private String certificateLocation;

But the value of certificateLocation is classpath:config/certificate.json. The value I want is the file location like : /home/user/project/scr/main/resources/config/certificate.json.

Or, are there a way to directly retrieve my file by URI, for example locahost:8889/... (8889 is my config server port).

EDIT 1: I cannot use absolute path from the server because I'm not the one who run it.

Thank you in advance.


Solution

  • I'd do

    @Value("${certificate.location}") private Resource certificateLocation;
    

    that way, your location is already a Resource that you can load, call getURI(), getFile().getAbsolutePath() etc. Since your value is prefixed with classpath:, you would have a ClassPathResource instance, which you can use for lot of things.