我在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>
但我没有按预期工作。有时它执行,有时没有。任何解决方案。
春季版是4