0

I have a Config Server up and running, with the relevant application.yml setting of

spring:
  application:
    name: config
    ...
      searchPaths:
        - '{application}'
        - '{application}/{profile}'

I would like to access a file that is not application.properties, something like myfile.txt. If I have the git layout

/myapp/nested/folder/myfile.txt

I want to be able to access that file. According to the Spring Config Server docs, I should be able to do this via /{name}/{profile}/{label}/{path}, but I can't get any paths to work.

TL;DR: How do I retrieve nested config files from a git repo via Config Server?

jeremysprofile
  • 10,028
  • 4
  • 33
  • 53
  • Try with slashes rather than `(_)`? – spencergibb Apr 09 '19 at 23:31
  • [The docs](https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html) specifically call out using `(_)` in place of `/` so that the delineations between `{label}` and `{application}` and etc. are parseable. I'll add those tries anyway to show they don't wok. – jeremysprofile Apr 10 '19 at 00:02
  • They are only for the placeholders in configuration, not the path of the file api. – spencergibb Apr 10 '19 at 18:21

1 Answers1

2

TL;DR: The documentation is wrong. The endpoint /{name}/{profile}/{label}/{path} should be written as /{application}/{profile}/{label}/{path}. You just need to make sure that one of your searchPaths/{path} can resolve your file.


First off, {label} is, as always, the git branch name (probably "master").

Second, {path} can can be an absolute path to the file. It uses /, i.e., myapp/nested/folder/myfile.txt, not (_) as is required in {application} or {label}.

Third, the search paths in the question are set to '{application}' and '{application}/{profile}', along with the default search path of /, the git repo's root directory. These define the places Config Server will search for a plain text file as:

/{expanded application}/{path}
/{expanded application}/{profile}/{path}
/{path}

Note that only {application} can be expanded into multiple folders with (_) and that only {path} can include multiple folders with /. For instance, with these searchPaths and a file located at /myapp/nested/folder/myfile.txt, the following requests are valid:

/asdf/asdf/master/myapp/nested/folder/myfile.txt
/myapp/asdf/master/nested/folder/myfile.txt
/myapp/nested/master/folder/myfile.txt
/myapp(_)nested(_)folder/asdf/master/myfile.txt
/myapp(_)nested/folder/master/myfile.txt

where asdf can be any arbitrary string.

jeremysprofile
  • 10,028
  • 4
  • 33
  • 53
  • I can certainly create a config server and specifiy a path like this `http://localhost:8888/foo/default/master/nested/hello.txt` that correctly gets files in a directory. – spencergibb Apr 10 '19 at 18:22
  • It looks like you're right. It is possible to have a full path specified using `/`. I wish this were documented anywhere on that "serving plain text files" page instead of only having top-level files. – jeremysprofile Apr 10 '19 at 18:32
  • Edited my answer, thanks for the help. I'd like to do that! hopefully I'll get to it sometime this week. – jeremysprofile Apr 10 '19 at 18:53
  • I think the `{name}` field is wrong, since it is being mapped to `{application}` in the `searchPaths` I set, and is called `{application}` everywhere else in the documentation. The other parts were just unclear as there was no example with a nested filepath. – jeremysprofile Apr 10 '19 at 22:54