Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use withLogger of RetryTemplateBuilder to avoid reflections #2545

Open
wants to merge 1 commit into
base: 4.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,23 @@

package org.springframework.cloud.config.client;

import java.lang.reflect.Field;

import org.apache.commons.logging.Log;

import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.ReflectionUtils;

public final class RetryTemplateFactory {

private static final Field field;

static {
field = ReflectionUtils.findField(RetryTemplate.class, "logger");
if (field != null) {
ReflectionUtils.makeAccessible(field);
}
}

private RetryTemplateFactory() {

}

public static RetryTemplate create(RetryProperties properties, Log log) {
RetryTemplate retryTemplate = RetryTemplate.builder()
return RetryTemplate.builder()
.maxAttempts(properties.getMaxAttempts())
.exponentialBackoff(properties.getInitialInterval(), properties.getMultiplier(),
properties.getMaxInterval(), properties.isUseRandomPolicy())
.withLogger(log)
.build();
try {
field.set(retryTemplate, log);
}
catch (IllegalAccessException e) {
if (log.isErrorEnabled()) {
log.error("error setting retry log", e);
}
}
return retryTemplate;
}

}
6 changes: 6 additions & 0 deletions spring-cloud-config-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<jgit.version>6.6.1.202309021850-r</jgit.version>
<spring-vault.version>3.1.1</spring-vault.version>
<spring-credhub.version>2.1.1.RELEASE</spring-credhub.version>
<spring-retry.version>2.0.10</spring-retry.version>
</properties>
<dependencyManagement>
<dependencies>
Expand All @@ -41,6 +42,11 @@
<artifactId>spring-cloud-config-monitor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>${spring-retry.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.vault</groupId>
<artifactId>spring-vault-core</artifactId>
Expand Down