如何解决字符串常量引用作为Annotation属性的值会导致编译错误
我正在使用属性文件来获取@Scheduled
批注属性的值。我能够从属性文件中获取值,但是当我尝试将String常量引用传递给Annotation属性时,就会引发编译时异常
@Slf4j
@CompileStatic
class TestJobService {
static lazyInit = false
public static String jobInterval = getSomePropertiesFileValues?.fixedRateInMS instanceof String? getSomePropertiesFileValues.fixedRateInMS:'10000'
@Scheduled(fixedDelayString = TestJobService.jobInterval)
void executeEveryTenSeconds() {
def date = new Date()
println date.format('yyyy/MM/dd HH:mm',TimeZone.getTimeZone('IST'))
}
}
属性“ fixedDelayString”应具有类型“ java.lang.String”;但 在中找到类型“ java.lang.Object” @ org.springframework.scheduling.annotation.Scheduled
然后我尝试使用String传递:
@Slf4j
@CompileStatic
class TestJobService {
static lazyInit = false
@Scheduled(fixedDelayString = '${getSomePropertiesFileValues.fixedRateInMS}')
void executeEveryTenSeconds() {
def date = new Date()
println date.format('yyyy/MM/dd HH:mm',TimeZone.getTimeZone('IST'))
}
}
OR
public static final String jobInterval = getSomePropertiesFileValues?.fixedRateInMS instanceof String? getSomePropertiesFileValues.fixedRateInMS:'10000'
防止将变量视为内联常量,并且编译器抱怨不是内联常量。
我知道使用单引号'${getSomePropertiesFileValues.fixedRateInMS}'
可以使编译器知道我想要GString行为。但是我不知道这是Groovy中的bug还是其功能,我需要以其他方式实现该功能才能将字符串值作为注释属性传递。任何线索或帮助都是非常明显的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。