3

I have a working spring boot application and I am trying to remove some properties from application.yaml file and read them from an embedded config server in the same app. At the moment, I am trying to read properties from file system through "native" profile type, and I am planning to later replace this with S3. Also, I am trying to read the configuration directly from backend repository as explained here https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#_embedding_the_config_server , rather than connecting through an endpoint.

If you want to read the configuration for an application directly from the backend repository (instead of from the config server), you basically want an embedded config server with no endpoints. You can switch off the endpoints entirely by not using the @EnableConfigServer annotation (set spring.cloud.config.server.bootstrap=true).

I have introduced following changes to my existing application to achieve this.

Added following dependencies to pom.xml

  • spring-cloud-starter-config
  • spring-cloud-config-server
  • spring-cloud-config-client

application-dev.yaml

spring:
 could:
  bootstrap:
   enabled: true

bootstrap.yaml

spring:
  profiles:
    active: composite
  cloud:
    config:
      server:
        composite:
        - type: native
          search-locations: file:C:\\Users\\chamila\\config-test\\config
#      bootstrap: true

The required properties are saved in a different application-dev.yaml file at the above file path. I have not used @EnableConfigServer annotation from my app class, as I want connect directly without the endpoint.

However, still my program is failing to read the properties from the config-server. I tried setting spring.cloud.config.server.bootstrap=true and spring.cloud.bootstrap.enabled=true from both application-dev.yaml and bootstrap.yaml, but it didn't work?

Any idea what I am missing? I note that I never specified how to connect to the config-server in my application-dev.yaml file also. Is that an issue?

Any help is highly appreciated.

Chamila Wijayarathna
  • 1,815
  • 5
  • 30
  • 54

2 Answers2

1

I created a sample project of an embedded Configuration Server which uses a custom repository:

The initial problem was that the custom EnvironmentRepository was not available via bootstrap, as described in this issue.

Claudio Tasso
  • 417
  • 5
  • 13
0

I followed https://cloud.spring.io/spring-cloud-config/reference/html/#_embedding_the_config_server and achieved the expected result.

  1. Add spring-cloud-starter-bootstrap to your dependencies as suggested in https://github.com/taxone/embedded-config-server.
  2. Make sure that composite profile is active when you start the app.
  3. Verify that your native configuration is added by finding a log message from NativeEnvironmentRepository during startup.
  4. (Optional) Remove spring.cloud.bootstrap.enabled from application-dev.yaml.
  5. (Optional) Remove spring-cloud-config-client dependency as it is included in both spring-cloud-starter-config and spring-cloud-config-server.
  6. (Further steps) Use @RefreshScope on a spring bean to achieve dynamic properties. Requires POST actuator/refresh.