In this tutorial, you will learn how to configure your Spring Cloud Config Server to use a native file system as a backend.
For a step-by-step series of video lessons, please check this page: Spring Boot Microservices and Spring Cloud.
Create Spring Cloud Config Server
Please read this tutorial: Spring Cloud Config Server and Config Client, to learn how to create your very first Spring Cloud Config Server.
Native File System as Backend
To configure your Spring Cloud Config Server to use the native file system as a backend, update the application.properties file of your Spring Cloud Config Server with the following details:
spring.profiles.active=native spring.cloud.config.server.native.searchLocations=file://${user.home}/Desktop/dev
where:
- spring.profiles.active – Is used to specify an active Spring Boot Profile name. To be able to use the native file system, the profile name used must be “native“. If you use Git as a backend for your Spring Cloud Config server, then you would use “git” as a profile name.
- spring.cloud.config.server.native.searchLocations – Is used to specify the location where the configuration properties file will need to be searched. I have created a new configuration properties file for my application and placed it in a folder called “dev” on the Desktop. The file is called PhotoAppAPIConfigServer.properties, where the PhotoAppAPIConfigServer is the application name of my Spring Cloud Config Server. Your Spring Cloud Config Application name will be different, and its value is specified in a property called spring.application.name.
As an example, I have put only one property into my PhotoAppAPIConfigServer.properties file. The content of my configuration properties file is following:
token.secret = jf9i4jg47fhdnj58yrgh35dhjf8403jdh375jf34970000
Postman HTTP Request to Preview Configuration Properties
To see if your Spring Cloud Config Server can read the configuration properties stored in a native file system, you can use the Postman HTTP client to send an HTTP Request to the following URL:
http://localhost:<Port Number>/<Spring Cloud Config Application name>/native
where:
- Port Number – is a port number on which your Spring Cloud Config Server is running,
- Spring Cloud Config Application name – is the name of your Spring Cloud Config Server specified with a spring.application.name property.
- native – is a profile name. To configure our Spring Cloud Config Server to use the native file system as a backend, we had to use “native” as a value of spring.profiles.active property. This is why we use native in the URL path of our HTTP GET Request. You can also use “default” in the URL path, and it will also work.
To send HTTP GET Request, you can also use CURL:
curl -X GET http://localhost:8012/PhotoAppAPIConfigServer/native
Spring Cloud Config Server Response
If you send an HTTP GET request using a Postman HTTP client or a simple CURL command, as shown above, you should expect the following HTTP Response.
{ "name": "PhotoAppAPIConfigServer", "profiles": [ "native" ], "label": null, "version": null, "state": null, "propertySources": [ { "name": "file:///Users/skargopolov/Desktop/dev/PhotoAppAPIConfigServer.properties", "source": { "token.secret": "jf9i4jg47fhdnj58yrgh35dhjf8403jdh375jf34970000" } } ] }
where:
- token.secret – is just a property stored in a configuration file. In your case, a list of properties will be different.
I hope this tutorial was helpful to you.
If you want to learn more about Spring Cloud, check out this list of Spring Cloud Tutorials. And have a look at the below list of online video courses that teach Spring Cloud.