无法通过spring.cloud.config禁用spring cloud配置enabled:false

dy1byipe  于 2021-07-15  发布在  Java
关注(0)|答案(5)|浏览(974)

让我先说一下,我不是直接使用springcloud配置,它是通过springcloudhystrixstarter传递的。
仅使用时 @EnableHystrix ,springcloud也尝试定位一个配置服务器,预期没有成功,因为我没有使用配置服务器。据我所知,应用程序运行得很好,但问题出在状态检查上。健康秀 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
    }
}

如果我做得不对的话,任何方向都会很感激的。

mjqavswn

mjqavswn1#

引导过程中需要配置服务器,父属性源就是从这里来的。看起来你只需要移动你的手 spring.cloud.config.enabled 属性设置为bootstrap.yml(或.properties)。

5sxhfpxr

5sxhfpxr2#

您可以将引导属性或yml放入资源目录或应用程序目录,然后添加 spring.cloud.config.enabled=false . 或
您可以通过添加环境变量禁用spring cloud config server客户端: SPRING_CLOUD_CONFIG_ENABLED=false
如果将参数传递给springapplication.run,可以通过向应用程序添加参数来禁用配置服务器客户端: public static void main(String[] args) throws Exception { SpringApplication.run(YourApplication.class, args); } 并通过以下方式启动应用程序: java -jar yourapplication.jar --spring.cloud.config.enabled=false

k3bvogb1

k3bvogb13#

我有同样的问题,我想有配置服务器禁用(因为我们不需要到目前为止),但上述属性是不正确的rc1至少。

spring.cloud.enabled

应该是:

spring.cloud.config.enabled
btxsgosb

btxsgosb4#

我尝试了上面所有的更改,但配置客户端始终没有停止。
我能够禁用它的唯一方法是在我的项目的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>
fdx2calv

fdx2calv5#

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

相关问题