개발중인 STS 웹 앱에서 cron으로 작업 중이며 cron 타이머에서 SpringMailSender를 실행하려고 할 때 문자열 형식 문제가 있습니다. 외부 속성 파일에서 cron의 값을 가져오고 어떤 이유로 좋아하지 않는 것 같습니다. 어떤 아이디어? 내 코드는 다음과 같습니다.
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());
}
}
외부 속성 파일의 정보는 다음과 같습니다.
timer.time=0 0 8 ? 1/1 MON#2 *
내가 얻는 오류는 이것이다 ...
"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)}"
@Scheduled
주석 (즉 PROPERT 자리를 사용하기위한 지원을하고있다 ${...}
). 이 작업을 수행하려면 속성 자리 표시자를 구성해야합니다.
<context:placholder-configurer location="path/to/your/external.properties" />
그런 다음 @Scheduled
주석에서 파일의 속성을 간단히 참조 할 수 있습니다.
@Scheduled(cron="${timer.time}")
이렇게하면 ApplicationContext
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다