Spring Cloud Config Server – File System as a Backend

In this tutorial you will learn how to configure your Spring Cloud Config Server to use 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

To learn how to create your very first Spring Cloud Config Server please ready this tutorial: Spring Cloud Config Server and Config Client.

Native File System as Backend

To configure your Spring Cloud Config Server to use native file system as a backend follow the below steps:

  • Update 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 profile name. To be able to use 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 Desktop. The file is called PhotoAppAPIConfigServer.properties where the PhotoAppAPIConfigServer is 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 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 a 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 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 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 Servere Response

If you send HTTP GET request using Postman HTTP client or using 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 are looking to lean more about Spring Cloud have a look at these list of Spring Cloud Tutorials. And have a look at the below list of online video courses that teach Spring Cloud.


Leave a Reply

Your email address will not be published. Required fields are marked *