Spring Cloud 参考文档(嵌入Config Server)

8次阅读

共计 867 个字符,预计需要花费 3 分钟才能阅读完成。

嵌入 Config Server
Config Server 作为独立应用程序运行最佳,但是,如果需要,你可以将其嵌入另一个应用程序中,为此,请使用 @EnableConfigServer 注解。在这种情况下,名为 spring.cloud.config.server.bootstrap 的可选属性非常有用,它是一个标志,指示服务器是否应从其自己的远程存储库配置自身,默认情况下,该标志处于关闭状态,因为它可能会延迟启动。但是,当嵌入到另一个应用程序中时,以与任何其他应用程序相同的方式初始化是有意义的,将 spring.cloud.config.server.bootstrap 设置为 true 时,还必须使用组合环境存储库配置,例如:
spring:
application:
name: configserver
profiles:
active: composite
cloud:
config:
server:
composite:
– type: native
search-locations: ${HOME}/Desktop/config
bootstrap: true
如果使用 bootstrap 标志,则配置服务器需要在 bootstrap.yml 中配置其名称和存储库 URI。
要更改服务器端点的位置,你可以(可选)设置 spring.cloud.config.server.prefix(例如,/config),以便在前缀下提供资源,前缀应该开始但不以 / 结束,它应用于 Config Server 中的 @RequestMappings(即 Spring Boot server.servletPath 和 server.contextPath 前缀下面)。
如果要直接从后端存储库(而不是从配置服务器)读取应用程序的配置,你基本上需要一个没有端点的嵌入式配置服务器,你可以通过不使用 @EnableConfigServer 注解完全关闭端点(设置 spring.cloud.config.server.bootstrap=true)。

上一篇:提供纯文本配置访问
下一篇:推送通知和 Spring Cloud Bus

正文完
 0