![](/img/trans.png)
[英]Can I use another Annotation as the value of the Spring @Qualifier?
[英]Can I use a Spring @Value variable from properties in another annotation?
我目前有一个来自属性文件的变量,声明为:
@Value("${retryLimit}")
private int retryLimit;
在这种情况下,我想在注释中使用而不是硬编码常量“3”:
@Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000))
这可能吗?
我试过了:
@Retryable(maxAttempts = @Value("${retryLimit}"), backoff = @Backoff(delay = 2000))
但是我收到以下编译错误:
"Incompatible types. Found: 'org.springframework.beans.factory.annotation.Value', required: 'int'"
无需在另一个注释标签中使用@value
。 只需使用@value
。 它会起作用。
@Retryable(maxAttempts = "${retryLimit}", backoff = @Backoff(delay = 2000))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.