简体   繁体   中英

How to point spring-cloud-config server to a git folder inside a git repo

Please help me to resole the following problem.I would like to have a folder for each micro service in git repo. Please refer the sample structure I have inside git repo. https://github.com/tech-vishesh/config-server_properties

If we have same properties under different folder
        like
        ms-one
        |--- application.properties
        |--- application-prod.properties
        |--- application-dev.properties
        ms-two
        |--- application.properties
        |--- application-prod.properties
        |--- application-dev.properties

        we have define search path in spring cloud config bootstrap file
        spring.cloud.config.server.git.search-paths=ms-one,ms-two
        Now we have to load profile in client application then how we can load the profile?
        I have define
        spring.application.name=application
        spring.profiles.active=dev
        but how to define which folder.

    Current spring boot version 2.2.5

It can be solved. The trick is to give search-path {application} without quotes as given below. It was a little tricky as spring documentation mentions it as '{application}' , probably spring developers just wanted to highlight it with quotes.

In spring cloud server add below mentioned search path-

spring.cloud.config.server.git.search-paths={application}

instead of

spring.cloud.config.server.git.search-paths='{application}'

This sets the search path(on server side) equal to the name of client application name .

now if your microservices/applications- they should have spring.application.name as below-

spring.application.name=ms-one

and

spring.application.name=ms-two 

they would be looking at the properties file within their respective folders of ms-one and ms-two.

You need to set next property for Spring Cloud Config Server :

spring.cloud.config.server.git.search-paths='{application}'

in this case your client application name will be used as a search path for the folder.

Point to your git repo and set the subfolder in the searchPaths

spring.cloud.config.server.git.uri=https://github.com/sarat9/config-server-spring-boot
spring.cloud.config.server.git.searchPaths=config-repo

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