Reputation: 4306
I have a scheduler to clean the DB
@Scheduled(fixedDelay = @Value("#{new Long('${clean_up.period}')}"))
public void cleanStatInfoTable() {
List<StateInfo> infoLis=stateInfoRepository.findAllByCreatedDateBefore(LocalDateTime.now().minusHours(1));
stateInfoRepository.deleteInBatch(infoLis);
}
But it produce compilation error
Incompatible types. Found: 'org.springframework.beans.factory.annotation.Value', required: 'long'
I also tried the form @Scheduled(fixedDelay = @Value("${obi.payments.state_info.clean_up.period}"))
but still the same issue
How can i inject a long
value into the fixedDelay
property in Scheduled
annotation ?
Upvotes: 3
Views: 2414
Reputation: 125312
Use fixedDelayString
instead what you have now. You are making things overly complex.
@Scheduled(fixedDelayString = "${clean_up.period}"))
Upvotes: 10
Reputation: 825
Try this :
@Value("${clean_up.period}")
private Long delay;
------
@Scheduled(fixedDelay = delay)
Upvotes: -2