Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

415
Views
¿Cómo inyectar propiedades de configuración en Spring Boot a la anotación Spring Retry?

En la aplicación Spring Boot, defino algunas propiedades de configuración en el archivo yaml como se muestra a continuación.

 my.app.maxAttempts = 10 my.app.backOffDelay = 500L

Y un frijol de ejemplo

 @ConfigurationProperties(prefix = "my.app") public class ConfigProperties { private int maxAttempts; private long backOffDelay; public int getMaxAttempts() { return maxAttempts; } public void setMaxAttempts(int maxAttempts) { this.maxAttempts = maxAttempts; } public void setBackOffDelay(long backOffDelay) { this.backOffDelay = backOffDelay; } public long getBackOffDelay() { return backOffDelay; }

¿Cómo puedo inyectar los valores de my.app.maxAttempts y my.app.backOffdelay en la anotación Spring Retry? En el siguiente ejemplo, quiero reemplazar el valor 10 de maxAttempts y 500L del valor de retroceso con las referencias correspondientes de las propiedades de configuración.

 @Retryable(maxAttempts=10, include=TimeoutException.class, backoff=@Backoff(value = 500L))
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

A partir de spring-retry-1.2.0 , podemos usar propiedades configurables en la anotación @Retryable.

Use "maxAttemptsExpression", Consulte el código a continuación para el uso,

 @Retryable(maxAttemptsExpression = "#{${my.app.maxAttempts}}", backoff = @Backoff(delayExpression = "#{${my.app. backOffDelay}}"))

No funcionará si usa una versión anterior a la 1.2.0. Tampoco necesita ninguna clase de propiedad configurable.

about 4 years ago · Santiago Trujillo Report

0

También puede usar beans existentes en atributos de expresión.

 @Retryable(include = RuntimeException.class, maxAttemptsExpression = "#{@retryProperties.getMaxAttempts()}", backoff = @Backoff(delayExpression = "#{@retryProperties.getBackOffInitialInterval()}", maxDelayExpression = "#{@retryProperties.getBackOffMaxInterval" + "()}", multiplierExpression = "#{@retryProperties.getBackOffIntervalMultiplier()}")) String perform(); @Recover String recover(RuntimeException exception);

dónde

propiedades de reintento

es su bean que tiene propiedades relacionadas con el reintento como en su caso.

about 4 years ago · Santiago Trujillo Report

0

Puede usar Spring EL como se muestra a continuación para cargar las propiedades:

 @Retryable(maxAttempts="${my.app.maxAttempts}", include=TimeoutException.class, backoff=@Backoff(value ="${my.app.backOffDelay}"))
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!