Currently, I can use String arguments using SpEL
as follows:
@Autowired private ParameterService parameterService; @Scheduled(cron = "#{parameterService.findByCode('cron')}")
It works fine but if I want a long constant it will not be work :
@Autowired 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.
Advertisement
Answer
Use fixedDelayString instead:
@Scheduled(fixedDelayString = "#{parameterService.findByCode('fixedDelay')}"))