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

jtoj6r0c  于 2023-05-21  发布在  Spring
关注(0)|答案(6)|浏览(172)

我先声明一下,我没有直接使用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
    }
}

任何方向将不胜感激,如果它似乎我没有这样做是正确的。

5vf7fwbs

5vf7fwbs1#

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

vom3gejh

vom3gejh2#

  • 您可以将引导属性或yml放到资源目录或应用程序目录中,然后添加spring.cloud.config.enabled=false。或
  • 您可以通过添加环境变量来禁用Spring Cloud Config Server客户端:SPRING_CLOUD_CONFIG_ENABLED=false
  • 如果您将参数传递给www.example.com,则可以通过向应用添加参数来禁用Config服务器客户端SpringApplication.run:
public static void main(String[] args) throws Exception {
    SpringApplication.run(YourApplication.class, args);
}

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

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

kgsdhlau3#

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

spring.cloud.enabled

应为:

spring.cloud.config.enabled
pgpifvop

pgpifvop4#

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

ejk8hzay5#

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

0dxa2lsx

0dxa2lsx6#

这些都没有帮助我,我需要禁用spring cloud client bootstrap从服务器进行集成测试,所以任何面临同样问题的人都可以使用帮助我的东西:

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

}

然后使用以下内容注解测试:

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

相关问题