Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在spring boot中从application.properties文件创建可配置的可重试maxAttempts和backoff_Java_Spring_Multithreading_Spring Boot_Spring Retry - Fatal编程技术网

Java 如何在spring boot中从application.properties文件创建可配置的可重试maxAttempts和backoff

Java 如何在spring boot中从application.properties文件创建可配置的可重试maxAttempts和backoff,java,spring,multithreading,spring-boot,spring-retry,Java,Spring,Multithreading,Spring Boot,Spring Retry,下面是参数,试图使其可配置 @Async("threadPoolTaskExecutor") @Retryable(value = MessagingException.class, maxAttempts = 2, backoff = @Backoff(delay = 5000)) 我做了以下的改变 application.properties文件 my.app.maxAttempts = 2 my.app.backOffDelay = 5000 及 但是得到下面的错误。 不兼容类型。fo

下面是参数,试图使其可配置

@Async("threadPoolTaskExecutor")
@Retryable(value = MessagingException.class, maxAttempts = 2, backoff = @Backoff(delay = 5000))
我做了以下的改变 application.properties文件

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

但是得到下面的错误。 不兼容类型。foundjava.lang.String。必需的“int”

在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}"))
这应该有效

使用表达式

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

这应该行得通

是的,我最近做过。此外,如果愿意,您可以使用该Spring EL调用方法并从其他位置加载。如何测试Retryable是否与配置的最大尝试一起工作?@PraveenD使用RetryListenerSupport记录尝试的次数是我最近做的。此外,如果愿意,您可以使用该Spring EL调用方法并从其他位置加载。如何测试Retryable是否与配置的最大尝试一起工作?@PraveenD使用RetryListenerSupport记录尝试次数