Melad Basilius
Melad Basilius

Reputation: 4306

incompatible types. Found: 'org.springframework.beans.factory.annotation.Value', required: 'long'

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

Answers (2)

M. Deinum
M. Deinum

Reputation: 125312

Use fixedDelayString instead what you have now. You are making things overly complex.

@Scheduled(fixedDelayString = "${clean_up.period}"))

Upvotes: 10

Nick
Nick

Reputation: 825

Try this :

@Value("${clean_up.period}")
private Long delay;

------
@Scheduled(fixedDelay = delay)

Upvotes: -2

Related Questions