스프링 부트 자동 구성 @EnableScheduling
을 사용하여 cron 작업을 만들려고합니다. fixedRateString
이 하드 코드 된 경우 작업이 완벽하게 작동합니다. 그러나 SpEL을 사용하여 값을 제공하려고 시도하면 성공하지 못합니다.SpEL이 인스턴스 변수에 액세스 할 수 없습니다.
// 콩 인스턴스화 JavaConfig에서
@Bean
public AlertbotJob2 getAlertJob2() {
AlertbotJob2 alertbotJob2 = new AlertbotJob2("alertId", "alertName", "alertSubject", "6000", true);
return alertbotJob2;
}
콩 정의
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");
}
}
예외는 :: 구문 분석에 실패했습니다. 중첩 예외는 org.springframework.expression.spel.SpelEvaluationException입니다 : EL1008E : 'org.springframework.beans.factory.config.BeanExpressionContext'유형의 객체에서 'this'속성 또는 필드를 찾을 수 없습니다 - public이 아닐 수도 있습니까?
저는 트리거 값을 동적으로 설정하려고합니다. 도와주세요.
음, 그 방법을 시도했지만 제대로 작동하지 않았습니다. 데이터베이스 구성을 읽은 후 프로그램 방식으로 bean을 작성하고 있습니다. 프로토 타입 범위로 **@someBean**.cronPattern을 만들 수 있는지 알아야합니다. – zikzakjack
아니요; SpEL 표현식이 주석이 상주하는 클래스의 인스턴스를 직접 참조 할 수있는 방법은 없습니다. –