Spring @Scheduled 在使用注解时执行任务两次 [英] Spring @Scheduled is executing task twice when using annotations
本文介绍了Spring @Scheduled 在使用注解时执行任务两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 Spring @Scheduled 注释创建了任务,但由于某种原因它执行了两次任务.我的 Spring Framework 版本是 3.0.2.
I have made task using Spring @Scheduled annotation, but for some reason it is executing task twice. My Spring Framework version is 3.0.2.
@Service
public class ReportService {
@Scheduled(fixedDelay=1000 * 60 * 60* 24)
@Transactional
public void dailyReportTask()
{
... code here ...
}
}
这是我的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<task:scheduler id="taskScheduler" />
<task:executor id="taskExecutor" pool-size="1" />
<task:annotation-driven executor="taskExecutor"
scheduler="taskScheduler" />
</beans>
推荐答案
这是因为上下文监听器而发生的
it is happening because of context listener
直接删除
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
来自 web.xml
它应该可以工作.
from web.xml
it should work.
这篇关于Spring @Scheduled 在使用注解时执行任务两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文