Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring计划注释它是如何工作的_Java_Spring_Spring Mvc_Quartz Scheduler_Spring Scheduled - Fatal编程技术网

Java Spring计划注释它是如何工作的

Java Spring计划注释它是如何工作的,java,spring,spring-mvc,quartz-scheduler,spring-scheduled,Java,Spring,Spring Mvc,Quartz Scheduler,Spring Scheduled,我已经用java创建了一个函数。该函数应该每天午夜运行 //My function this function is within UpdateService Class @Scheduled(cron = "0 0 0 * * ?") public static void UpdateFn() { try { System.out.println("-----------Background Task Running----------------");

我已经用java创建了一个函数。该函数应该每天午夜运行

//My function this function is within UpdateService Class
@Scheduled(cron = "0 0 0 * * ?")
public static void UpdateFn() {
    try {
        System.out.println("-----------Background Task Running----------------");
        //code to update some data every day
        System.out.println("-----------Background Task Ending----------------");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

//My xml configuration
 <task:annotation-driven />
    <bean id="UpdateTask" class="com.ss.utility.UpdateService"></bean>
  </beans>
//我的函数此函数在UpdateService类中
@已计划(cron=“0**?”)
公共静态void UpdateFn(){
试一试{
System.out.println(“--------------后台任务运行-----------------”;
//每天更新一些数据的代码
System.out.println(“--------------后台任务结束-----------------”;
}捕获(例外e){
e、 printStackTrace();
}
}
//我的xml配置
但我没有按预期工作。有时执行,有时不执行。对此有任何解决方案


Spring版本是4

您不应该为此使用静态方法。请尝试使用以下代码:

@Scheduled(cron = "0 0 0 * * ?")
public void UpdateFn() {
    try {
        System.out.println("-----------Background Task Running----------------");
        //code to update some data every day
        System.out.println("-----------Background Task Ending----------------");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

它在静态方法上不起作用。谢谢。我会修改并检查它