java - Spring Cloud Config Client 应用程序不使用 bootstrap.properties
问题描述
我正在阅读一些关于 Spring Cloud 的教程,但我的配置客户端应用程序遇到了问题。我有一个在 Linux 机器上运行的 Eureka 服务器,在我的 Mac 上我有一个配置服务器,它正在与 Eureka 服务器正确注册。我使用 spring 初始化器生成了一个配置客户端应用程序。我拥有的依赖项是:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
我有一个这样的 bootstrap.properties 文件:
spring.application.name=config-client-app
spring.cloud.config.discovery.enabled=true
eureka.client.serviceUrl.defaultZone=http://192.168.1.125:8761/eureka/
当配置客户端应用程序启动时,它无法向 Eureka 服务器注册,因为它正在寻找在本地机器上运行的实例。如果我将它放在 application.properties 中,那么它会在 eureka 注册,但名称为 UNKNOWN。
eureka.client.serviceUrl.defaultZone=http://192.168.1.125:8761/eureka/
由此看来,配置客户端应用程序没有使用 bootstrap.properties 文件。根据我在类路径上使用 spring-cloud-starter-config 所读到的内容,它应该在启动时查找 bootstrap.properties 文件。
主应用程序类具有以下注释。
@SpringBootApplication
@EnableDiscoveryClient
@RestController
我在这里想要实现的是让客户端向 eureka 询问配置服务器的位置,然后从那里获取它的配置。
谢谢安德鲁
解决方案
根据这里的这篇文章,我认为我已经解决了这个问题。Spring Cloud Config:客户端不尝试连接到配置服务器
我添加了
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
到我的 pom.xml ,现在它似乎按预期工作。
推荐阅读
- nginx - 应用程序中具有相对 URI 的 kubernetes 入口配置
- html - 即使我使用“d-flex justify-content-end”,“搜索栏”也不会在右侧移动?
- javascript - 如何触发用户在 React 中输入的数据的呈现?
- python - 将元素从字典添加到具有关键条件的其他字典
- isabelle - 如何从伊莎贝尔转储中恢复证明?
- swift - Swift:尝试测试 ObservedObject 变量是否为 nil 时的 EXC_BREAKPOINT
- buffer - 我用 VHDL 编写的 Fifo 缓冲区不起作用
- kotlin - Kotlin:userNameRealmPasswordDigestProvider 已弃用错误
- html - 如何摆脱列表中的溢出切割div?
- docker - Dockerfile 中的 COPY 命令。如何从上一层复制