spring-cloud-config icon indicating copy to clipboard operation
spring-cloud-config copied to clipboard

Application tries to reach out to config server even when its disabled

Open mbhuie opened this issue 9 years ago • 12 comments

Create a new application from start.spring.io. Include Spring Cloud Config Client.

		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-config</artifactId>
		</dependency>

Disable spring.cloud.config.

spring:
  cloud:
    config:
      enabled: false

In logs I see

2017-10-26 18:01:24.715  INFO 9480 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
2017-10-26 18:01:26.428  WARN 9480 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: label not found

I think this is causing #104 for me.

I think the problem is this property is completely ignored.

In

ConfigServiceBootstrapConfiguration

	@Bean
	@ConditionalOnMissingBean(ConfigServicePropertySourceLocator.class)
	@ConditionalOnProperty(value = "spring.cloud.config.enabled", matchIfMissing = true)
	public ConfigServicePropertySourceLocator configServicePropertySource(ConfigClientProperties properties) {
		ConfigServicePropertySourceLocator locator = new ConfigServicePropertySourceLocator(
				properties);
		return locator;
	}

shouldn't it be

	@Bean
	@ConditionalOnMissingBean(ConfigServicePropertySourceLocator.class)
	@ConditionalOnProperty(value = "spring.cloud.config.enabled", matchIfMissing = true,  havingValue="true")
	public ConfigServicePropertySourceLocator configServicePropertySource(ConfigClientProperties properties) {
		ConfigServicePropertySourceLocator locator = new ConfigServicePropertySourceLocator(
				properties);
		return locator;
	}

mbhuie avatar Oct 26 '17 22:10 mbhuie

Makes sense, want to submit a PR?

ryanjbaxter avatar Nov 06 '17 20:11 ryanjbaxter

@ryanjbaxter The problem still exists. I wanted to make a PR but see now that ConfigServicePropertySourceLocator has no @Conditional annotation. Does it mean that it can not be configured at all? Is it possible to use spring-boot-starter-actuator with health check without config servers?

grined avatar Jun 26 '18 07:06 grined

Both conditionals still exist as far as I can see https://github.com/spring-cloud/spring-cloud-config/blob/6710237c1080df1c1a776eb27768696b2582ca8f/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfiguration.java#L54

ryanjbaxter avatar Jun 26 '18 15:06 ryanjbaxter

Is there a way to disable config server? Face the same issue in 2.0.4

Al-Y avatar Dec 10 '18 11:12 Al-Y

Nothing has changed.

ryanjbaxter avatar Dec 10 '18 22:12 ryanjbaxter

The same problem even I use bootstrap.yml as config file, Spring Could 1.5.9

rickywu avatar Dec 11 '18 09:12 rickywu

If I run as java -cp com.company.package.jar:./lib/* com.company.package.MainClass or compile with Class-Path in MANIFEST.MF file then run as java -jar com.company.package.jar then this problem fixed, so you should check properties file name and class path.

rickywu avatar Dec 12 '18 08:12 rickywu

Just realized that this property needs to be set in bootstrap.yml not application.yml. Can you try that and let us know?

ryanjbaxter avatar Dec 13 '18 17:12 ryanjbaxter

Hi @ryanjbaxter ,

I tried spring.cloud.config.enabled=false in bootstrap.properties, the client is still looking for config server. And I am using custom-rest-template

spring-cloud-starter-config: 2.0.2.RELEASE

AndrewLaBabies avatar Dec 17 '18 17:12 AndrewLaBabies

@AndrewLaBabies if you are using custom bootstrap config, it will need to be @ConditionalOnProperty("spring.cloud.config.enabled"). I was unable to recreate the problem you are having. Setting that property disabled config client.

Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.

spencergibb avatar Dec 17 '18 17:12 spencergibb

Thanks @spencergibb , I applied @ConditionalOnProperty("spring.cloud.config.enabled") on the configuration class (contains bean ConfigServicePropertySourceLocator), it works now. The client stopped finding config server. Thanks.

AndrewLaBabies avatar Dec 19 '18 02:12 AndrewLaBabies

Thanks for following up.

spencergibb avatar Dec 19 '18 03:12 spencergibb