I am a newbie to the Spring Bootstrap process and trying to understand the flow to write my own BootstrapRegistryInitializer. In the sample below on Line 42 where is the "context" variable coming from? It is not defined as a local variable and there is no base class to inherit it from? Also since this is the bootstrap flow there is no Autowiring magic. Is there any detailed dev documentation on the bootstrap workflow for Cloud config?

https://github.com/spring-cloud/spring-cloud-config/blob/3e101db0852b6325f031e1c108e19ea75ef51684/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientRetryBootstrapper.java#L42

Thanks again for the help.

Comment From: ryanjbaxter

We are passing a lambda to that method which is an implementation of InstanceSupplier. Spring Boot will call this InstanceSupplier.get passing BootstrapContext. This is the context variable you see in the lambda in that code.

These pointers to Spring Boot might help https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BootstrapRegistry.java#L65 https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BootstrapRegistry.java#L106

Comment From: dharshanrg

Hi Ryan,

How do I get access to the BootstrapContext in the initialize method of the BootstrapRegistryInitializer? The reason is that I need the bindContext to read some properties in the conf file to decide which TextEncryptor to use. Currently this context is only available in the register() method. Depending on the configured properties I might not register a custom encryptor - so I need to know this before I call the register() method.

Comment From: ryanjbaxter

Here is an example

https://github.com/spring-cloud/spring-cloud-netflix/blob/main/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapper.java#L67-L70

You can also get a BindHandler from the context as well I believe

Comment From: dharshanrg

Hi Ryan,

The problem is that the context is only available inside the register() function. Depending on the configured properties I might not register a TextEncryptor - hence I need to read the config files before the register() function. Is there a way to get access to the BootStrapcontext?

Comment From: ryanjbaxter

Not that I know of, but within your InstanceProvider you should just be able to return null if the property does not have the right value.

Comment From: dharshanrg

Hi Ryan,

In case I do not want to use my custom TextEncryptor I would like to fallback to the default TextEncryptor. I guess instead of returning null, I can copy the code and build and return the default TextEncryptor?

Comment From: ryanjbaxter

Yup

Comment From: dharshanrg

Thanks. I will work on that flow. Thanks again for your help!