设置嵌入式 Spring Config Server

问题描述 投票:0回答:1

我正在设置 Spring Cloud Config,以允许我们的应用程序之一在运行时更改某些配置属性。至于现在它只是一个由 Spring Config Server 管理的应用程序,我想保持部署简单,我想将 Config Server 和应用程序作为一个部署。据我所知,这被支持为“嵌入配置服务器”。

为了使其运行,我使用 https://spring.io/guides/gs/centralized-configuration 作为基础来设置单独的配置服务器和客户端。我还在

file:/Users/mibutec/projects/config-repo
中设置了一个配置存储库,其中包含

message=Hello, Mibutec

这个设置工作正常,当调用curl

localhost:8888/message
时,我看到了我的消息
Hello, Mibutec
。一切都好!

现在我尝试让配置服务器也在客户端应用程序中运行。

我更改了客户端应用程序的application.properties,如下所示:

server.port=8888
spring.application.name=a-bootiful-client
management.endpoints.web.exposure.include=*

# spring.config.import=http://localhost:8888/
spring.profiles.active=composite
spring.cloud.config.server.composite[0].type=git
spring.cloud.config.server.composite[0].uri=file:/Users/mibutec/projects/config-repo
spring.cloud.config.server.bootstrap=true

我通过将

@EnableConfigServer
添加到主类来启用配置服务器。

我没有对某些

bootstrap.properties
做任何事情,因为我知道这只是 Spring Boot 所必需的 < 2.4 and I'm beyond.

但是,我没有让客户端更新它的属性。每当我打电话

localhost:8888/message
我都会看到我的消息
Hello default

配置服务器本身似乎工作正常:调用

curl localhost:8888/a-bootful-client-composite.yml
返回

message: Hello, Mibutec

我还尝试通过执行器刷新应用程序,这也没有改变任何东西。

所以我的问题:

  • 我理解“嵌入配置服务器”的想法了吗?它应该能够直接配置我的应用程序吗?
  • 从客户端配置中删除
    spring.config.import
    是否正确?我知道它被替换为
    spring.cloud.config.server.bootstrap
    。我还尝试将其配置为我的内部配置服务器的地址,但比我在启动时得到的地址
    Config data location 'http://localhost:8888/' does not exist
    这是有道理的,因为端口似乎尚未启动。
spring spring-cloud spring-cloud-config
1个回答
0
投票

因此,要在嵌入式模式下运行配置服务器,您仍然需要

bootstrap.properties
bootstrap.yml

这需要在那里:

spring.profiles.active=composite
spring.cloud.config.server.composite[0].type=git
spring.cloud.config.server.composite[0].uri=file:/Users/mibutec/projects/config-repo
spring.cloud.config.server.bootstrap=true

那么就不再需要

spring.config.import
@EnableConfigServer
了。

© www.soinside.com 2019 - 2024. All rights reserved.