在 stack-overflow 中也提出了同样的问题,但没有找到正确的解决方案。我的应用程序中有以下配置。如果其他应用程序在 8888 上运行,它会抱怨同样的问题,甚至卡住。
有人有办法避免这种情况吗?
日志:
2024-03-20 14:32:22.078 INFO 18756 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2024-03-20 14:32:22.110 INFO 18756 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
依赖关系:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<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.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
应用程序.yml
spring:
application:
name: my-app
profiles:
active: stage
---
spring:
cloud:
config:
label: dev
config:
import: configserver:http://myconfig:5232
activate:
on-profile: stage
---
spring:
cloud:
config:
label: prod
config:
import: optional:configserver:http://config.abc.com
activate:
on-profile: prod
---
您正在使用
spring-cloud-starter-bootstrap
,它启用 旧配置处理。但是,在您的属性中,您正在使用配置配置处理的新方法。
所以你有两个选择:
删除
spring-cloud-starter-bootstrap
。
使用旧版配置处理,这意味着您需要创建一个
bootstrap.properties
或 bootstrap.yml
文件,其中包含:
spring:
application:
name: my-app
cloud:
config:
uri: http://myconfig:5232