I am working with cron in a STS web app I am developing and I am having a string format issue when trying to run the SpringMailSender on a cron timer. I am pulling the value for the cron from an external properties file and for some reason it does not seem to be liking it. Any ideas? Here is my code...
public class Timer {
@Autowired
private ApplicationContext ctx;
@Autowired
private SpringMailSender springMailSender;
@Scheduled(cron="${ctx.getMessage('timer.time', null, null)}")
public void timer()
{
System.out.println("timer() in Timer Class has been stepped into");
try {
springMailSender.sendMail();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Method executed on every 2nd Monday of each month. Current time is :: "+ new Date());
}
}
The info in the external properties file looks like this...
timer.time=0 0 8 ? 1/1 MON#2 *
the error I am getting is this...
"java.lang.IllegalStateException: Encountered invalid @Scheduled method 'timer': Could not resolve placeholder 'ctx.getMessage('timer.time', null, null)' in string value "${ctx.getMessage('timer.time', null, null)}"