Code: Select all
package foo.bar.baz;
@ConfigurationProperties(prefix = "apns")
public record ApnsConfiguration(
Duration gracefulShutdownTimeout,
int maxAttempts,
Duration minDelay,
Duration maxDelay,
List endpoints
Ich habe es versucht: < /p>
Code: Select all
@Retryable(
retryFor = RetryableException.class,
maxAttemptsExpression = "#{@apnsConfiguration.maxAttempts}",
backoff = @Backoff(
delayExpression =
"#{apnsConfiguration.minDelay.toMillis}",
maxDelayExpression =
"#{@apnsConfiguration.maxDelay.toMillis}",
multiplier = BACKOFF_MULTIPLIER)
)
< /code>
, wenn diese Tests (und Startups) bei diesen Fehlern fehlschlagen: < /p>
EL1058E: A problem occurred when trying to resolve bean 'apnsConfiguration': 'Could not resolve bean reference against BeanFactory'
org.springframework.expression.spel.SpelEvaluationException: EL1058E: A problem occurred when trying to resolve bean 'apnsConfiguration': 'Could not resolve bean reference against BeanFactory'
[snip]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'apnsConfiguration' available
at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:925)
< /code>
Ich habe nicht verstanden, warum sie die Bean nicht gefunden habe, also habe ich die Namen aller Bohnen verwendet: < /p>
@EventListener
public void handleContextRefreshed(final ContextRefreshedEvent event) {
Arrays.stream(event.getApplicationContext().getBeanDefinitionNames())
.forEach(name -> log.info("Bean name: {}", name));
}
< /code>
Wenn ich mir diese Ausgabe ansehe, sehe ich Folgendes: < /p>
Bean name: baz-foo.bar.baz.ApnsConfiguration
< /code>
Also habe ich als nächstes die Frühlingsausdrücke so geändert, wie es: < /p>
sindmaxAttemptsExpression = "#{@baz-foo.bar.baz.ApnsConfiguration.maxAttempts}"
Code: Select all
@Component
public final class ApnsMessageConverter implements Converter
Code: Select all
maxAttemptsExpression = "#{(@'baz-foo.bar.baz..ApnsConfiguration').maxAttempts}"