简体   繁体   English

启动后如何更改Spring Boot服务器的时间

[英]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.

相关问题 Spring Boot 应用程序启动后设置系统属性是否合适? - Is it proper to set System property after Spring Boot application has started? AppiumServerHasNotBeenStartedLocallyException: 本地 appium 服务器尚未启动 - AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started 带有Apache Camel的Spring Boot应用程序启动后立即关闭 - Spring boot app with Apache Camel shuts down right after it has started Spring Boot + React:当数据已在其中一个选项卡上发布到服务器时重新加载应用程序选项卡 - Spring Boot + React: reload application tabs when data has been posted to the server on one of the tabs Spring boot:java.lang.IllegalStateException:响应提交后无法调用sendError() - Spring boot : java.lang.IllegalStateException: Cannot call sendError() after the response has been committed 更改属性文件后,Maven无法构建Spring Boot应用程序(无法解析配置类) - Maven can not build spring boot app after properties file has been changed (Failed to parse configuration class) 在控制器中处理完@ModelAttribute 后,如何在 Spring MVC 中重置它? - How to reset a @ModelAttribute in Spring MVC after it has been processed in the controller? Spring 云Eureka服务器在启动eureka客户端服务后立即重启。 (升级JDK和Spring引导版本后。) - Spring Cloud Eureka server restarts as soon as eureka client service is started. (After upgrading JDK and Spring Boot version.) Spring Boot更改服务器端口 - Spring boot change server port 显示JFrame后如何更改它的内容(java) - how to change the contents of a JFrame after it has been displayed (java)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM