嵌入Config ServerConfig 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