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

Discovery setting can't set in a different profile when use Discovery First Lookup.

Open tanwan opened this issue 4 years ago • 3 comments

Describe the bug When I set discovery setting in specific profile(e.g. application-test.yml), it will raise an exception.

java.lang.NullPointerException: null
	at org.springframework.cloud.config.client.ConfigServerInstanceProvider.getConfigServerInstances(ConfigServerInstanceProvider.java:57) ~[spring-cloud-config-client-3.1.0-RC1.jar:3.1.0-RC1]
	at org.springframework.cloud.config.client.ConfigServerInstanceMonitor.refresh(ConfigServerInstanceMonitor.java:90) ~[spring-cloud-config-client-3.1.0-RC1.jar:3.1.0-RC1]

The bootstrapContext register Binder with activationContext after contributors process imports. So in ConfigServerConfigDataLocationResolver#resolveProfileSpecific method, the bootstrapContext has no activationContext, and the resolverContext has activationContext. Therefore, resolverContext resolved spring.cloud.config.discovery.enabled is true, However bootstrapContext resolved result is false. It cause the ConfigServerInstanceProvider.Function register in EurekaConfigServerBootstrapper is null.

Sample The configuration in application-test.yml

eureka:
  client:
    serviceUrl:
      defaultZone: http://127.0.0.1:8761/eureka/
spring:
  config:
    import: 'optional:configserver:'
  cloud:
    config:
      enabled: true
      discovery:
        enabled: true
        serviceId: configserver

tanwan avatar Nov 22 '21 09:11 tanwan

Does this happen in 2020.0.4 as well?

ryanjbaxter avatar Nov 22 '21 21:11 ryanjbaxter

Yes, I tried 2020.0.4 and 2021.0.0-RC1, they all happened.

tanwan avatar Nov 23 '21 00:11 tanwan

There is a similar issue in 2021.0.1, Boot 2.6.6; setting spring.cloud.config.discovery.enabled=true by default, and spring.cloud.config.discovery.enabled=false for a profile specific document in the same file produces an InactiveConfigDataAccessException if the profile isn't active.

pmahony893 avatar Apr 06 '22 15:04 pmahony893