【问题标题】:Cannot disable Spring Cloud Config via spring.cloud.config.enabled:false无法通过 spring.cloud.config.enabled:false 禁用 Spring Cloud Config
【发布时间】:2015-02-18 13:46:05
【问题描述】:

让我先说我没有直接使用 Spring Cloud Config,它是通过 Spring Cloud Hystrix starter 传递的。

当仅使用@EnableHystrix 时,Spring Cloud 也会尝试定位配置服务器,但预期不成功,因为我没有使用。据我所知,该应用程序运行良好,但问题在于状态检查。健康显示DOWN,因为没有配置服务器。

浏览项目的源代码,我希望 spring.cloud.config.enabled=false 禁用此功能链,但这不是我所看到的。

升级到1.0.0.RC1(添加此属性)并使用@EnableCircuitBreaker后:

{
    status: "DOWN",
    discovery: {
        status: "DOWN",
        discoveryClient: {
            status: "DOWN",
            error: "org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.cloud.client.discovery.DiscoveryClient] is defined"
        }
    },
    diskSpace: {
        status: "UP",
        free: 358479622144,
        threshold: 10485760
    },
    hystrix: {
        status: "UP"
    },
    configServer: {
        status: "DOWN",
        error: "org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http: //localhost: 8888/bootstrap/default/master":Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect"
    }
}

检查 configprops 端点后,似乎我的属性被覆盖了。请注意,父级已启用 configClient。

parent: {
    configClientProperties: {
        prefix: "spring.cloud.config",
        properties: {
            password: null,
            discovery: {
                enabled: false,
                serviceId: "CONFIGSERVER"
            },
            name: "bootstrap",
            label: "master",
            env: "default",
            uri: "http://localhost:8888",
            enabled: true,
            failFast: false,
            username: null
        }
    }
},
configClientProperties: {
    prefix: "spring.cloud.config",
    properties: {
        password: null,
        discovery: {
            enabled: false,
            serviceId: "CONFIGSERVER"
        },
        name: "bootstrap",
        label: "master",
        env: "default",
        uri: "http://localhost:8888",
        enabled: false,
        failFast: false,
        username: null
    }
}

如果我似乎没有正确执行此操作,任何方向都将不胜感激。

【问题讨论】:

  • 你用的是什么版本的Spring Cloud?
  • 我使用的是 1.0.0.M3 的 spring-cloud-starter-parent,它引入了相同版本的 spring-cloud-starter-hystrix。我也用这些信息更新了我的问题,谢谢。
  • 试试 RC1(刚刚发布)。我认为该标志是最近添加(或扩展)的。
  • 谢谢,@DaveSyer - 我会试一试并报告。
  • @DaveSyer - 我已将我的发现添加到原始帖子而不是 cmets。我不确定这种变化对我来说是好是坏。我还注意到一些可能会覆盖我的配置的父属性。

标签: spring spring-boot netflix spring-cloud hystrix


【解决方案1】:

这些都没有帮助我,我需要从服务器禁用 Spring Cloud 客户端引导以进行集成测试,所以遇到同样问题的人可以使用对我有帮助的东西:

@ComponentScan(excludeFilters = {
    @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = PropertySourceBootstrapConfiguration.class),
})
public class TestApplication {

}

然后用以下方式注释您的测试:

@SpringBootTest(classes = TestApplication.class)
class SomeIntegrationTest {}

【讨论】:

    【解决方案2】:

    在引导期间需要配置服务器,这就是父属性源的来源。看起来您需要做的就是将您的 spring.cloud.config.enabled 属性移动到 bootstrap.yml(或 .properties)。

    【讨论】:

    • DiscoveryClient 中似乎还有一些剩余的云配置溢出。 ConfigServer 似乎已解决,但 DiscoveryClient 仍显示为 DOWN,尽管还添加了 spring.cloud.config.discovery.enabled: falsebootstrap.properties
    • 这是默认设置。并且发现没有连接到配置,所以我会说这是另一个问题(我们还没有对不同的依赖项组合进行太多测试)。在这里开始新帖子或在 github 中提出问题?
    • 我会这样做的。我会将此标记为已回答,因为它回答了原始问题。
    • 添加spring.cloud.config.enabled=false(而不是spring.config.enabled)到bootstrap.properties有助于消除Fetching config from server at : http://localhost:8888谢谢
    • 属性现在不是去掉了吗? github.com/spring-projects/spring-boot/wiki/…
    【解决方案3】:
    • 您可以将引导属性或 yml 放入资源目录 或您的应用程序目录并添加 spring.cloud.config.enabled=false。或
    • 您可以通过添加环境变量来禁用 spring cloud config server 客户端:SPRING_CLOUD_CONFIG_ENABLED=false OR
    • 如果您将参数传递给 SpringApplication.run 的参数,则可以通过向您的应用添加参数来禁用配置服务器客户端:

      public static void main(String[] args) throws Exception { SpringApplication.run(YourApplication.class, args); }

      并通过以下方式启动应用程序:

      java -jar yourapplication.jar --spring.cloud.config.enabled=false

    【讨论】:

      【解决方案4】:

      我尝试了上述所有更改,但配置客户端仍然没有停止。

      我能够通过在项目的 pom.xml 文件中使用以下排除项来禁用它的唯一方法。

      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter</artifactId>
          <exclusions>
              <exclusion>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-config-client</artifactId>
              </exclusion>
          </exclusions>
      </dependency>
      

      【讨论】:

      • 正是这个位置。现有的解决方案都不起作用,但这种排除方法并不是最好的选择。
      【解决方案5】:

      关于发现服务跟进(看起来没有其他帖子),设置 spring.cloud.config.discovery.enabled: false 对我有用,但前提是它是在 bootstrap(yml/properties) 中设置并且我从我的Application 班级。我想这意味着不能将该注释用于有时不会使用发现的任何服务。

      【讨论】:

        【解决方案6】:

        我遇到了同样的问题,我想禁用配置服务器(因为我们目前还不需要它)但上面提到的属性至少对于 RC1 是不正确的。

        spring.cloud.enabled
        

        应该是:

        spring.cloud.config.enabled
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-11-28
          • 2016-02-18
          • 2023-01-20
          • 2017-02-23
          • 2017-05-01
          • 1970-01-01
          相关资源
          最近更新 更多