如何连接我的 web.xml 以让任务每隔 n 秒发生一次。此外,我需要通过方法调用每 5 秒刷新一次服务器方法。
提前致谢
已解决:
http://javaprogrammingtips4u.blogspot.com/2010/05/how-to-implement-task-scheduler-job.html
最佳答案
您可以使用
注释所需的例程public class Foo {
@Scheduled(fixedDelay=5000)
public void Bar() {
// ...
}
}
但是为了让 Spring 找到并识别注解,你必须声明 Foo
类位于哪个基础包,并配置 Spring 来寻找调度任务。将以下内容放入您的 spring XML 配置中(不要忘记导入 XML 命名空间 context
和 task
)。
<context:component-scan base-package="com.company.scheduling"/>
<task:annotation-driven />
或者,您可以将@EnableScheduling 放在类声明之前,它会立即为您执行 XML 配置。
关于java - 如何在 Spring 框架中安排任务每 'N' 秒发生一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8479397/