[英]How to change the Spring boot server time after it has been started
I am building an application using spring boot which has couple of scheduling tasks which are executed one month after it is created. 我正在使用Spring Boot构建一个应用程序,该应用程序具有几个计划任务,这些任务在创建后一个月执行。 For testing this service, I need to change the server time to a time after one month, when the server is running. 为了测试此服务,我需要将服务器时间更改为一个月后服务器运行的时间。 Can you please guide through the steps of how to achieve this? 您能指导完成该步骤的步骤吗?
For testing purpose, i would suggest you to create your service method with Date as parameter. 为了进行测试,我建议您以Date为参数创建服务方法。 ex : 例如:
public void myScheduledTack(){
myDate = getCurrentDate();
myService.myMethod(myDate);
}
public getCurrentDate(){
return new Date();
}
With this pattern, you could mock the getCurrentDate method and test your service. 使用这种模式,您可以模拟getCurrentDate方法并测试您的服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.