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
Comment From: ryanjbaxter
Does this happen in 2020.0.4 as well?
Comment From: tanwan
Yes, I tried 2020.0.4 and 2021.0.0-RC1, they all happened.
Comment From: pmahony893
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.