8. 嵌入配置服务器

Config Server 作为独立的应用程序运行得最好,但如果需要,可以将其嵌入另一个 application 中。只需使用@EnableConfigServer annotation。在这种情况下可用的可选 property 是spring.cloud.config.server.bootstrap,它是一个 flag,表示服务器应该从自己的 remote repository 配置自己。 flag 默认是关闭的,因为它可以延迟启动,但是当嵌入另一个 application 时,初始化方法与任何其他 application 相同。

这应该是显而易见的,但请记住,如果使用 bootstrap flag,配置服务器将需要在bootstrap.yml中配置其 name 和 repository URI。

要更改服务器 endpoints 的位置,您可以(可选)设置spring.cloud.config.server.prefix,e.g. “/config”,以前缀提供资源。前缀应该开始但不以“/”结尾。它应用于配置服务器中的@RequestMappings(i.e.Spring Boot 前缀server.servletPathserver.contextPath下面)。

如果你想直接从后端 repository(而不是从配置服务器)读取_appiguration 的 configuration,它基本上是一个没有 endpoints 的嵌入式配置服务器。如果不使用@EnableConfigServer annotation(只需设置spring.cloud.config.server.bootstrap=true),则可以完全关闭 endpoints。

首页