convert SpEL output to long to use as an annotation argument

Tags: , ,

Currently, I can use String arguments using SpEL as follows:

private ParameterService parameterService;

@Scheduled(cron = "#{parameterService.findByCode('cron')}")

It works fine but if I want a long constant it will not be work :

private ParameterService parameterService;

@Scheduled(fixedDelay = "#{parameterService.findByCode('fixedDelay')}")
//error: incompatible types: String cannot be converted to long

@Scheduled(fixedDelay = Long.parseLong("#{parameterService.findByCode('fixedDelay')}"))
//error: element value must be a constant expression

So, How to fix it?

Also, I cannot give Long and it accepts only long

edit :

I have gone through many similar SpEL questions but there were no applicable solutions for my case.


Use fixedDelayString instead:

@Scheduled(fixedDelayString = "#{parameterService.findByCode('fixedDelay')}"))

Source: stackoverflow