首页 / 操作系统 / Linux / Spring 定时器执行两次
Spring错误笔记
Spring定时器执行两次因为导入了两次关于配置文件如下
<bean id="timeTaskService" class="xx.xxx.xxx.xxx.service.impl.na.TimeTaskService"/>
<task:scheduled-tasks scheduler="myScheduler"><!--30秒执行一次 -->
<task:scheduled ref="timeTaskService" method="checkHeartBeat" cron="0/30 * * * * ?"/>
</task:scheduled-tasks>
<task:scheduler id="myScheduler"/>对应的类有个定时执行检查的动作,但是动作中的日志每次输出两遍,一开始以为是log4j的输出导致的两条,找了半天没办法还是决定eclipse调试打印一下,输出竟然是两条,那么等于这个方法竟然执行了两次。
根绝网上提供的说法如果导入两次那么就可能出现这种情况,发现真的是因为导入了两次,因为在spring.xml中import中写的
<import resource="classpath*:config/**/spring*.xml"/>
而其他的包里面还包含了相同的spring.xml文件,且这个spring.xml还有这么一个导入<import resource="spring-job.xml" />
等于加载了不止一遍,上边导入的时候已经有了一个spring*.xml(可能也包含spring-job.xml了)而另一个又import了一次。
这个时候只要把spring.xml中import导入写成<import resource="classpath*:config/**/spring.xml"/>只导入spring.xml或者把另一个spring.xml中<import resource="spring-job.xml" />去掉即可。Spring中如何配置Hibernate事务 http://www.linuxidc.com/Linux/2013-12/93681.htmStruts2整合Spring方法及原理 http://www.linuxidc.com/Linux/2013-12/93692.htm基于 Spring 设计并实现 RESTful Web Services http://www.linuxidc.com/Linux/2013-10/91974.htmSpring-3.2.4 + Quartz-2.2.0集成实例 http://www.linuxidc.com/Linux/2013-10/91524.htm使用 Spring 进行单元测试 http://www.linuxidc.com/Linux/2013-09/89913.htm运用Spring注解实现Netty服务器端UDP应用程序 http://www.linuxidc.com/Linux/2013-09/89780.htmSpring 3.x 企业应用开发实战 PDF完整高清扫描版+源代码 http://www.linuxidc.com/Linux/2013-10/91357.htmSpring 的详细介绍:请点这里
Spring 的下载地址:请点这里本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-06/103615.htm