不兼容的类型。找到:"org.springframework.beans.factory.annotation.Value",必需:'long'



>我有一个调度程序来清理数据库

@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)

最新更新