java - 如果配置服务器关闭,Spring Cloud 配置客户端会加载本地属性

标签 java spring spring-boot spring-cloud spring-cloud-config

我正在尝试访问 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/

相关文章:

spring - 在 Spring 中 Autowiring 注释而不使用组件扫描

java - 所需的 MultipartFile 参数 'files' 不存在 - MultipartyEntityBuilder

mysql - 使用 Spring Data JPA 自定义存储库方法将数据从 csv 加载到 mysql 表

java - 我可以在同一个 URI 上配置 HTML 和 Spring Data REST JSON 吗?

java - 如何运行 junit 集成测试 - 禁用任何数据库层?

java - Spring Data Jpa获取没有实体表示的数据

java - 使用 Spring Cloud 从微服务访问外部 IP

java - 如何以编程方式创建信任/ keystore ?

java - 在 Intellij 中调试时,我可以在返回之前找出返回值吗?

java - Eclipse在Android上导入MoPub SDK报错