我正在尝试访问 Spring Cloud 配置服务器,但它已关闭。我仍然想使用本地 application.properties 测试应用程序。有什么办法可以做到这一点吗?
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
bootstrap.yml
server:
port: 8086
spring:
application:
name: PromoMS
security:
basic:
enabled: false
management:
security:
enabled: false
cloud:
config:
fail-fast: true
discovery:
enabled: true
service-id: ms-config-server
我遇到以下异常
java.lang.IllegalStateException: No instances found of configserver (ms-config-server)
at org.springframework.cloud.config.client.ConfigServerInstanceProvider.getConfigServerInstances(ConfigServerInstanceProvider.java:48) ~[spring-cloud-config-client-2.2.2.RELEASE.jar:2.2.2.RELEASE]
最佳答案
要禁用 spring-cloud-config 并使用本地属性,您需要将此属性添加到 bootstrap.yml
中:
spring.cloud.config.enabled=false
然后仅当您需要通过应用程序参数运行应用程序时才启用它,如下所示:
java -jar your-application-name.jar --spring.cloud.config.enabled=true
关于java - 如果配置服务器关闭,Spring Cloud 配置客户端会加载本地属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60927370/