类型转换中基数的含义

时间:2019-12-22 17:39:07

标签: java spring kotlin

在Spring中,传递给注释的值必须是编译时常量。在以下代码段中,如果我将参数openTimeoutExpression的值与"\${circuit.breaker.open.timeout}"一起传递,则会出现以下错误:

org.springframework.expression.EvaluationException: Cannot convert value '5000' to type 'java.lang.Long'
at org.springframework.expression.common.ExpressionUtils.convertTypedValue(ExpressionUtils.java:63) ~[spring-expression-5.2.0.RELEASE.jar:5.2.0.RELEASE]

但是,如果我使用"#{\${circuit.breaker.open.timeout}}",则值'5000'将正确转换为Long。在表达式#{EXPRESSION}中具有基数是什么意思?

代码段:

@CircuitBreaker(maxAttemptsExpression="\${circuit.breaker.max.attempts}",
        openTimeoutExpression="#{\${circuit.breaker.open.timeout}}",
        resetTimeoutExpression="#{\${circuit.breaker.reset.timeout}}")
fun notifyCampaignStatus(callbackUrl: String, campaignStatus: CampaignStatus): Boolean {
    retryTemplate.execute(RetryCallback<Boolean, Exception>{
        println("Retry.................... No. ${it.retryCount}")
        val result = restTemplateBuilder.
                build().exchange(callbackUrl,
                HttpMethod.POST,
                HttpEntity(campaignStatus),
                String::class.java)
        return@RetryCallback result.statusCode == HttpStatus.OK
    })
    return false
}

0 个答案:

没有答案