user1549440
user1549440

Reputation: 77

Spring Cloud Config Server: How to override shared properties in app specific file

I would like to share some properties across several applications as suggested below, and I would expect to be able to override the value so if I have x=1 in application-dev.properties I should be able to override x in my application specific file i.e in my case test_app-dev.properties contains x=2. So when I make a call to http://local host:8888/test_app/dev x=1 trumps all. Files are in git. Shouldn’t it be returning x=2 or am I misunderstanding the intent of shared properties?

In https://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html, paragraph "2.1.5 Sharing Configuration With All Applications". It says:

With file-based (i.e. git, svn and native) repositories, resources with file names in application* are shared between all client applications (so application.properties, application.yml, application-*.properties etc.). You can use resources with these file names to configure global defaults and have them overridden by application-specific files as necessary.

Upvotes: 0

Views: 1762

Answers (3)

Paramesh Korrakuti
Paramesh Korrakuti

Reputation: 2067

Initially myself also faced the issue. After looked at @user1549440 answer, got an idea on how to use common properties. After arranged the sharable configuration folder as a first searchable path, it's working as expected. Just added working example for handy solution.

Below is the example configuration in configuration-server.

server:
  port: 8888
spring:
  cloud:
    config:
      server:
        git:
          uri: file://app/configurations
          default-label: master
          search-paths:
            - 'common*'
            - 'petstore*'
            - 'inventory*'
  info:
     app:
       name: Configuration Server
       description: Spring Cloud Configuration Server
       version: 1.0.0
  security: 
    user: 
      name: myname
      password: mypass

Below is the sample folder structure for the applications.

├── app
│   └── configurations
│       ├── common
│       │   ├── application-dev.yml
│       │   ├── application-test.yml
│       │   ├── application-stg.yml
│       │   └── application-prod.yml
│       ├── inventory
│       │   ├── petstore-dev.yml
│       │   ├── petstore-test.yml
│       │   ├── petstore-stg.yml
│       │   └── petstore-prod.yml
│       └── petstore
│           ├── inventory-dev.yml
│           ├── inventory-test.yml
│           ├── inventory-stg.yml
│           └── inventory-prod.yml

Upvotes: 1

user1549440
user1549440

Reputation: 77

I found the issue I had the order incorrect in my spring.cloud.config.server.git.searchPaths

Upvotes: 0

Niket Shah
Niket Shah

Reputation: 341

If you are using git based repositories, check if files are committed or not. Seems to be the same problem as mentioned in thread - https://github.com/spring-cloud/spring-cloud-config/issues/32

Hope that will helps.

Upvotes: 0

Related Questions