I am trying to make use of Spring Boot AutoConfigured @EnableScheduling to create a cron job. Job triggers perfectly fine if the fixedRateString is hardcoded. However it does not succeed if I try to make use of SpEL to supply the value.
//Bean Instantiation in JavaConfig
@Bean
public AlertbotJob2 getAlertJob2() {
AlertbotJob2 alertbotJob2 = new AlertbotJob2("alertId", "alertName", "alertSubject", "6000", true);
return alertbotJob2;
}
Bean Definition
public class AlertbotJob2 {
String alertId;
String alertName;
String alertSubject;
public String cronPattern;
boolean isActive;
public AlertbotJob2() {
}
public AlertbotJob2(String alertId, String alertName, String alertSubject, String cronPattern, boolean isActive) {
super();
this.alertId = alertId;
this.alertName = alertName;
this.alertSubject = alertSubject;
this.cronPattern = cronPattern;
this.isActive = isActive;
}
@Scheduled(initialDelay = 60000, fixedRateString = "#{this.cronPattern}")
public void doTheJob() {
System.out.println("DoSomething");
}
}
Exception is :: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'this' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
I am just trying to set the trigger values dynamically. Please help.