简体   繁体   中英

spring.cloud.config.server.native.search-locations does not work with placeholders in Spring Cloud Config server

I use File system backend ( spring.profiles.active=native ) to load configuration files.

What I want to achieve is to have separate folder per application where all the configuration of appropriate component is stored eg /configs/TestApp1/*.yml, /configs/TestApp2/*.yml

Documentation tells that this can be done using placeholder {application} in search-locations property (according to Spring Cloud Config Server documentation http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_server ). However this does not do the trick.

I have the following config in application.yml of configuration server

server:
  port: 8000

spring:
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/configs/{application}

 profiles:
    active: native

When I make HTTP GET request to endpoint: http://localhost:8000/TestApp1/dev I do not get configuration from the Config Server as it does not replace placeholder to client application name (at least I think it should work in this way) and tries to look in the following directories:

Skipped config file 'classpath:/configs/{application}/TestApp1-dev.xml' resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.xml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1.xml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.yml' resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.yml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1.yml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.properties' resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.properties' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1.properties' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.yaml' resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1-dev.yaml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/TestApp1.yaml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.xml' resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.xml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application.xml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.yml' resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.yml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application.yml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.properties' resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.properties' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application.properties' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.yaml' resource not found
Skipped config file 'classpath:/configs/{application}/application-dev.yaml' for profile dev resource not found
Skipped config file 'classpath:/configs/{application}/application.yaml' for profile dev resource not found

Note: I tried to debug Spring sources but it seems that placeholders are not replaced in search-locations property. Well, there is also a chance that I might have missed/misunderstood something:)

Maybe someone could advice how can I have separate configuration directory per application in Spring Cloud Config Server?

I did a test with milestone version of Spring Cloud Brixton.M5 and placeholder {application} in search-locations is working as expected.

With Spring Cloud version 2021.0.0, use searchLocations .

spring:
  application:
    name: config-service
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          searchLocations: classpath:/config

server:
  port: 8888

Make sure you are using @EnableConfigServer annotation in your main application.

eg

@SpringBootApplication
@EnableConfigServer
public class ConfigurationServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigurationServerApplication.class, args);
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM