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

Native support for RetryTemplateFactory as it uses reflections to access the field logger of RetryTemplate

Open klopfdreh opened this issue 1 year ago • 3 comments

Describe the bug We wanted to use Spring Cloud Config Client within a native image. During the startup of our application we saw a NullPointerException

java.lang.NullPointerException
at org.springframework.cloud.config.client.RetryTemplateFactory.create(RetryTemplateFactory.java:47)
at org.springframework.cloud.config.client.ConfigClientRetryBootstrapper.lambda$initialize$1(ConfigClientRetryBootstrapper.java:46)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:92)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:61)
at org.springframework.boot.context.config.ConfigDataLoaders.load(ConfigDataLoaders.java:96)

We had a look into RetryTemplateFactory and saw field = ReflectionUtils.findField(RetryTemplate.class, "logger"); in line 31 and field.set(retryTemplate, log); in line 47.

There is no reflect-config.json provided to describe this access.

Sample N/A

klopfdreh avatar Jul 10 '24 14:07 klopfdreh

same for me..I solved it by adding to reflect-config.json

[
  {
    "name": "org.springframework.retry.support.RetryTemplate",
    "allDeclaredFields": true,
    "allDeclaredMethods": true,
    "allDeclaredConstructors": true
  },
  {
    "name": "org.springframework.cloud.config.client.RetryTemplateFactory",
    "allDeclaredMethods": true,
    "allDeclaredConstructors": true
  }
]

AlexGreg avatar Jul 26 '24 08:07 AlexGreg

Hey @AlexGreg

thanks that you also commented this issue!

Exactly this needs to be provided by spring-cloud-config-client 👍

Edit: As this is a Spring Boot project the existing RuntimeHintsRegistrar can be used to apply those reflection hints.

klopfdreh avatar Jul 26 '24 11:07 klopfdreh

@ryanjbaxter - should we do it this way or should I provide a RuntimeHintsRegistrar and apply the hints that way?

klopfdreh avatar Aug 24 '24 17:08 klopfdreh

@ryanjbaxter - I made a suggestion as this is a Spring Project I guess we are safe to use a RuntimeHintsRegistrar. See the PR for more information, please.

klopfdreh avatar Sep 02 '24 04:09 klopfdreh

@OlgaMaciaszek / @ryanjbaxter - sorry that I ask you directly for assistance, again. We are currently using Spring Cloud Config with Spring Retry and without the changes I suggested at Spring Cloud Config Client it can’t be used within a Spring Boot Native image without defining additional reflect definitions.

The changes are rather small and I only moved an existing class to its own file and added reflection hints to classes mentioned in this issue.

I would be very grateful if you could review those changes and may include them in one of the next releases.

klopfdreh avatar Sep 14 '24 17:09 klopfdreh

Hi @klopfdreh Thanks for reporting the issue. Will fix it shortly.

OlgaMaciaszek avatar Sep 16 '24 11:09 OlgaMaciaszek

@OlgaMaciaszek I fixed it already - just review and merge if everything is fine for you: https://github.com/spring-cloud/spring-cloud-config/pull/2456

klopfdreh avatar Sep 16 '24 12:09 klopfdreh

Thanks @klopfdreh - done.

OlgaMaciaszek avatar Sep 16 '24 12:09 OlgaMaciaszek