我有一个清理数据库的调度程序
@Scheduled(fixedDelay = @Value("#{new Long('${clean_up.period}')}"))
public void cleanStatInfoTable() {
List<StateInfo> infoLis=stateInfoRepository.findAllByCreatedDateBefore(LocalDateTime.now().minusHours(1));
stateInfoRepository.deleteInBatch(infoLis);
}
但是会产生编译错误
Incompatible types. Found: 'org.springframework.beans.factory.annotation.Value', required: 'long'
我还尝试了 @Scheduled(fixedDelay = @Value("${obi.payments.state_info.clean_up.period}")) 的形式
但还是一样的问题
如何将 long
值注入(inject) Scheduled
注释中的 fixedDelay
属性?
最佳答案
使用 fixedDelayString
代替您现在拥有的。你让事情变得过于复杂。
@Scheduled(fixedDelayString = "${clean_up.period}"))
关于java - 不兼容的类型。找到 : 'org.springframework.beans.factory.annotation.Value' , 需要: 'long',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59713189/