Learnitweb

Reading configurations from the filesystem location of Spring Cloud Config Server

1. Introduction

In the previous tutorial, we discussed how to read properties from Spring Cloud Config Server using Spring Cloud Config Client. In that example, we kept configurations in the classpath. In this tutorial, we’ll discuss reading configurations from the filesystem of the server.

Storing configurations in the filesystem is usually not used in production environments. Opting for a filesystem backend provides a straightforward method to initiate your project swiftly and facilitates easy testing. If you want to use this approach in production, make sure that the filesystem is reliable and shared across all instances of the Config server. You should also make sure the security of the filesystem location and only authorized users have access to the location else anyone can see the configuration.

2. Setting config location to filesystem

To load the config files from the local classpath or file system, the “native” profile in the Config Server should be used.

spring.profiles.active=native

To specify the filesystem location, use the file: prefix for file resources. Without a file: prefix, the default is the classpath. Like any Spring Boot configuration, you can embed any ${}-style environment placeholders., for example file:///${user.home}/config-repo.

Note that absolute paths in Windows require an extra / .

Following is an example of application.yml with filesystem as the search location for configuration.

server:
  port: 8085
spring:
  application:
    name: configserver
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          search-locations: file:///D:/config

3. Conclusion

As you navigate the filesystem-based configuration setup, keep in mind the importance of security measures, version control, and proper organization of your configuration files. This approach is a quick way to get started and testing.