问题描述
我正在使用属性文件来获取@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 (将#修改为@)