>我有一个调度程序来清理数据库
@Scheduled(fixedDelay = @Value("#{new Long('${clean_up.period}')}"))
public void cleanStatInfoTable() {
List<StateInfo> infoLis=stateInfoRepository.findAllByCreatedDateBefore(LocalDateTime.now().minusHours(1));
stateInfoRepository.deleteInBatch(infoLis);
}
但它会产生编译错误
不兼容的类型。发现: 'org.springframework.beans.factory.annotation.Value', 必需: 'long'
我也尝试了表格@Scheduled(fixedDelay = @Value("${obi.payments.state_info.clean_up.period}"))
但仍然是同样的问题
如何将long
值注入Scheduled
注释中的fixedDelay
属性中?
改用fixedDelayString
你现在拥有的东西。你把事情弄得太复杂了。
@Scheduled(fixedDelayString = "${clean_up.period}"))
试试这个:
@Value("${clean_up.period}")
private Long delay;
------
@Scheduled(fixedDelay = delay)