无法通过 spring.cloud.config.enabled:false 禁用 Spring Cloud Config

问题描述 投票:0回答:7

首先我要说的是,我没有直接使用 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 spring-boot netflix spring-cloud hystrix
7个回答
41
投票

引导期间需要配置服务器,这就是父属性源的来源。看起来您需要做的就是将您的

spring.cloud.config.enabled
属性移动到 bootstrap.yml (或 .properties)。


16
投票
  • 您可以将引导属性或 yml 放入资源目录中 或您的应用程序目录并添加
    spring.cloud.config.enabled=false
    。或
  • 您可以通过添加环境变量来禁用 spring cloud config server 客户端:
    SPRING_CLOUD_CONFIG_ENABLED=false
    OR
  • 如果将 args 参数传递给 SpringApplication.run,则可以通过向应用程序添加参数来禁用配置服务器客户端:
public static void main(String[] args) throws Exception {
    SpringApplication.run(YourApplication.class, args);
}

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

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

13
投票

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

spring.cloud.enabled

应该是:

spring.cloud.config.enabled

6
投票

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

我能够通过在项目的 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>

1
投票

关于发现服务后续(看起来没有其他帖子),设置

spring.cloud.config.discovery.enabled: false
对我有用,但前提是它是在 bootstrap(yml/properties) 中设置的,并且如果我从我的
@EnableDiscoveryClient 中删除了 
Application
 注释
类。我想这意味着不能将该注释用于任何有时不使用发现的服务。


0
投票

这些都没有帮助我,我需要从服务器禁用 Spring Cloud 客户端引导程序来进行集成测试,所以任何面临同样问题的人都可以使用帮助我的内容:

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

}

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

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

0
投票

如果您已启用此功能,请先将其删除:

config:
    import: "optional:configserver:"

之后在您的 application.yml 中使用

spring.cloud.config.enabled

© www.soinside.com 2019 - 2024. All rights reserved.