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

30

首先声明,我并没有直接使用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? - Dave Syer
我正在使用spring-cloud-starter-parent的1.0.0.M3版本,它会引入相同版本的spring-cloud-starter-hystrix。我已经在问题中更新了这些信息,谢谢。 - bvulaj
尝试使用RC1(刚刚发布)。我认为该标志最近被添加(或扩展)。 - Dave Syer
谢谢,@DaveSyer - 我会尝试并回报。 - bvulaj
@DaveSyer - 我已将我的发现添加到原始帖子中,而不是评论中。我不确定这种改变对我来说是好是坏。我还注意到一些父属性可能会覆盖我的配置。 - bvulaj
7个回答

41

在引导过程中需要配置服务器,那里是父属性源的来源。看起来你所需要做的就是将spring.cloud.config.enabled属性移到bootstrap.yml(或.properties)中。


DiscoveryClient似乎仍存在一些残留的cloud-config泄漏。 ConfigServer似乎已经解决了,但是尽管在bootstrap.properties中添加了spring.cloud.config.discovery.enabled: falseDiscoveryClient仍显示为DOWN - bvulaj
那是默认设置。发现与配置无关,所以我认为这是另一个问题(我们尚未测试不同依赖项组合)。在此处开始新帖子或在 GitHub 上提出问题? - Dave Syer
我会这样做。我会标记为已回答,因为它回答了原始问题。 - bvulaj
1
bootstrap.properties 中添加 spring.cloud.config.enabled=false(而不是 spring.config.enabled)有助于消除 Fetching config from server at : http://localhost:8888,谢谢。 - AlexK
这个属性现在被移除了吗?https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.1-Release-Notes - Akshay

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

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
正是这种情况。所有现有的解决方案都不起作用,但这种排除方法并不是最好的选择。 - Battlefury
你是否将Spring Cloud配置属性添加到bootstrap.yaml文件中(而不是application.properties)? - Blue_Elephant
我通过包含 spring-cloud-starter-bootstrap 并注释掉 spring-cloud-starter-config 来实现。不需要排除任何内容。也许你也可以尝试一下这种方法。 - towi

1
关于发现服务的后续(似乎没有其他帖子),将 spring.cloud.config.discovery.enabled: false 设置为我有效,但只有在 bootstrap(yml/properties) 中设置并从我的 Application 类中删除 @EnableDiscoveryClient 注释时才有效。我想这意味着在某些时候不会使用发现的任何服务上都不能使用该注释。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接