gpt4 book ai didi

java - 如何在 spring boot 中从 application.properties 文件创建可配置的 Retryable maxAttempts 和 backoff

转载 作者:行者123 更新时间:2023-11-29 04:08:27 25 4
gpt4 key购买 nike

低于参数,试图使可配置

@Async("threadPoolTaskExecutor")
@Retryable(value = MessagingException.class, maxAttempts = 2, backoff = @Backoff(delay = 5000))

我做了以下更改application.properties 文件

my.app.maxAttempts = 2
my.app.backOffDelay = 5000

@Retryable(value = MessagingException.class, maxAttempts = "${my.app.maxAttempts}", backoff = @Backoff(delay = "${my.app.my.app.backOffDelay}"))

但是出现以下错误。不兼容的类型。找到java.lang.String。必需的“整数”

在我的 build.gradle 文件中

dependencies {
compile ("org.springframework.boot:spring-boot-starter-web")
compile ("org.springframework.boot:spring-boot-starter-mail:2.1.2.RELEASE")
compile ("org.springframework.boot:spring-boot-starter-security:2.1.2.RELEASE")
compile ("org.springframework.boot:spring-boot-starter-aop")
compile ("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-jdbc:2.1.0.RELEASE")
compile ("org.springframework.retry:spring-retry:1.2.4.RELEASE")
compile ("io.springfox:springfox-swagger2:2.9.2")
compile ("io.springfox:springfox-swagger-ui:2.9.2")
compile ("io.springfox:springfox-bean-validators:2.9.2")
compile ("javax.validation:validation-api:2.0.0.Final")
compile ("org.hibernate.validator:hibernate-validator")
compile ("org.hibernate.validator:hibernate-validator-annotation-processor")
// compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.9.8'
compile ("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.8")
compile("org.postgresql:postgresql")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('org.springframework.batch:spring-batch-test')
testCompile group: 'org.springframework.security', name: 'spring-security-test', version: '4.0.0.RELEASE'
}

最佳答案

使用表达式来

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

这应该可行

关于java - 如何在 spring boot 中从 application.properties 文件创建可配置的 Retryable maxAttempts 和 backoff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56697919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com