Embedding the Config Server
Config Server 最好作为独立应用程序运行。但是,如果有需要,您可以将其嵌入到另一个应用程序中。为此,请使用 `@EnableConfigServer`注释。在这种情况下,名为 `spring.cloud.config.server.bootstrap`的可选项很有用。它是一个标志,表示服务器是否应根据自己的远程存储库进行配置。默认情况下,该标志处于关闭状态,因为它可能会延迟启动。但是,当嵌入另一个应用程序时,按照与任何其他应用程序相同的方式初始化是有意义的。当将 `spring.cloud.config.server.bootstrap`设置为 `true`时,还必须使用 composite environment repository configuration。例如:
The Config Server runs best as a standalone application.
However, if need be, you can embed it in another application.
To do so, use the @EnableConfigServer
annotation.
An optional property named spring.cloud.config.server.bootstrap
can be useful in this case.
It is a flag to indicate whether the server should configure itself from its own remote repository.
By default, the flag is off, because it can delay startup.
However, when embedded in another application, it makes sense to initialize the same way as any other application.
When setting spring.cloud.config.server.bootstrap
to true
you must also use a composite environment repository configuration.
For example
spring:
application:
name: configserver
profiles:
active: composite
cloud:
config:
server:
composite:
- type: native
search-locations: ${HOME}/Desktop/config
bootstrap: true
如果您使用引导标志,则配置服务器需要在 |
If you use the bootstrap flag, the config server needs to have its name and repository URI configured in |
若要更改服务器端点的地址,你可以(可选地)设置 spring.cloud.config.server.prefix
(例如,/config
),以便在指定前缀下提供资源。该前缀应以 /
开头,但不应以 /
结尾。它将应用于 Config Server 中的 @RequestMappings
(即,Spring Boot server.servletPath
和 server.contextPath
前缀下)。
To change the location of the server endpoints, you can (optionally) set spring.cloud.config.server.prefix
(for example, /config
), to serve the resources under a prefix.
The prefix should start but not end with a /
.
It is applied to the @RequestMappings
in the Config Server (that is, underneath the Spring Boot server.servletPath
and server.contextPath
prefixes).
如果你想直接从后端存储库读取应用程序配置(而不是从配置服务器读取),那么你基本上希望有一个没有端点的嵌入式配置服务器。你可以通过不使用 @EnableConfigServer
注解(设置 spring.cloud.config.server.bootstrap=true
)完全关闭端点。
If you want to read the configuration for an application directly from the backend repository (instead of from the config server), you
basically want an embedded config server with no endpoints.
You can switch off the endpoints entirely by not using the @EnableConfigServer
annotation (set spring.cloud.config.server.bootstrap=true
).