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 标志,则配置服务器需要在 中配置其名称和存储库 URI。bootstrap.yml |
如果使用 bootstrap 标志,则配置服务器需要在 中配置其名称和存储库 URI。bootstrap.yml |
若要更改服务器终结点的位置,可以(可选)设置(例如,),以在前缀下提供资源。
前缀应以 .
它应用于 Config Server 中(即 Spring Boot 和前缀下方)。spring.cloud.config.server.prefix
/config
/
@RequestMappings
server.servletPath
server.contextPath
如果要直接从后端存储库(而不是从配置服务器)读取应用程序的配置,则
基本上想要一个没有端点的嵌入式配置服务器。
您可以通过不使用注释 (set ) 来完全关闭端点。@EnableConfigServer
spring.cloud.config.server.bootstrap=true