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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27569168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:15:49  来源:igfitidea点击:

Cannot disable Spring Cloud Config via spring.cloud.config.enabled:false

springspring-bootnetflixspring-cloudhystrix

提问by bvulaj

Let me preface this by saying that I'm not using Spring Cloud Config directly, it is transitive via Spring Cloud Hystrix starter.

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

When only using @EnableHystrix, Spring Cloud also tries to locate a configuration server, expectedly unsuccessfully, since I'm not using one. The application works just fine, as far as I can tell, but the problem is in the status checks. Health shows DOWNbecause there is no config server.

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

Browsing the source of the project, I'd expect spring.cloud.config.enabled=falseto disable this functionality chain, however this is not what I'm seeing.

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

After upgrading to 1.0.0.RC1(which adds this property) and using @EnableCircuitBreaker:

升级到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"
    }
}

After checking the configprops endpoint, it seemsthat my properties are being overridden. Note that the parent has the configClient enabled.

检查 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
    }
}

Any direction would be appreciated, if it seems I'm not doing this correctly.

任何方向将不胜感激,如果我似乎没有正确地做到这一点。

回答by Dave Syer

The config server is needed during bootstrap, and that's where the parent property sources come from. It looks like all you need to do is move your spring.cloud.config.enabledproperty to bootstrap.yml (or .properties).

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

回答by MiguelPuyol

I had the same problem, I wanted to have the config server disabled (as we do not need it so far) but the property mentioned above is not correct for RC1 at least.

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

spring.cloud.enabled

Should be:

应该:

spring.cloud.config.enabled

回答by Dániel Kis

  • You can put a bootstrap properties or yml to your resource direcotry or your applications directory and add spring.cloud.config.enabled=false. OR
  • You can disable spring cloud config server client by adding an environment variable: SPRING_CLOUD_CONFIG_ENABLED=falseOR
  • Config server client can be disabled by adding a parameter to your app, if you pass the args to parameters to SpringApplication.run:

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

    and start the app by:

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

  • 您可以将引导属性或 yml 放入您的资源目录或应用程序目录中,并添加 spring.cloud.config.enabled=false. 或者
  • 您可以通过添加环境变量来禁用 spring cloud config 服务器客户端:SPRING_CLOUD_CONFIG_ENABLED=false
  • 如果您将 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

回答by JMewada

I tried all of the above changes and still config client never stopped somehow.

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

The only way I was able to disable it by using following exclusion in my project's pom.xml file.

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

回答by Eric Sword

Regarding the discovery service followup (looks like no other posts on that), setting spring.cloud.config.discovery.enabled: falseworked for me, but only if it was set in bootstrap(yml/properties) and if I removed the @EnableDiscoveryClientannotation from my Applicationclass. I guess this means one cannot use that annotation for any service where discovery will not be used at times.

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