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

空扰寡人 提交于 2020-12-13 17:58:51

问题


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

回答1:


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.




回答2:


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 the properties file within their respective folders of ms-one and ms-two.



来源:https://stackoverflow.com/questions/60500158/how-to-point-spring-cloud-config-server-to-a-git-folder-inside-a-git-repo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!