简体   繁体   English

如何将 spring-cloud-config 服务器指向 git repo 内的 git 文件夹

[英]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.请帮我解决以下问题。我想在 git repo 中为每个微服务都有一个文件夹。 Please refer the sample structure I have inside git repo.请参考我在 git repo 中的示例结构。 https://github.com/tech-vishesh/config-server_properties 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.诀窍是给搜索路径{application}不带引号,如下所示。 It was a little tricky as spring documentation mentions it as '{application}' , probably spring developers just wanted to highlight it with quotes.这有点棘手,因为 spring 文档将其称为 '{application}' ,可能 spring 开发人员只是想用引号突出显示它。

In spring cloud server add below mentioned search path-在 spring 云服务器中添加下面提到的搜索路径-

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-

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.他们将查看 ms-one 和 ms-two 各自文件夹中的属性文件。

You need to set next property for Spring Cloud Config Server :您需要为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指向您的 git repo 并在searchPaths设置子文件夹

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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