简体   繁体   English

Spring 4.3.1计划任务运行两次

[英]Spring 4.3.1 scheduled task run twice

I have a problem while scheduling a task into an application scoped bean using spring 4.3.1. 使用Spring 4.3.1将任务调度到应用程序范围的Bean时遇到问题。 My code is something like this one: 我的代码是这样的:

@Component
@ApplicationScope
public class MyClassImpl implements MyClass {

   @Scheduled(fixedDelayString = "60000")
   @Transactional
   public void method() {
     do something...
   }
}

The scheduled method is runned twice. 计划的方法运行两次。 I debugged application context creation and it seems that the bean is loaded only one time as expected. 我调试了应用程序上下文创建,似乎该bean仅按预期加载了一次。 Do somebody has some suggestions? 有人有建议吗?

I added a BeanPostProcessor and I noticed that spring framework instantiate 2 beans one named MyClassImpl and one named scopedTarget.MyClassImpl any idea on how to avoid this behaviour? 我添加了一个BeanPostProcessor,我注意到spring框架实例化了2个bean,一个名为MyClassImpl ,另一个名为scopedTarget.MyClassImpl,关于如何避免这种行为的任何想法?

解决了创建一个新类的问题,该类未实现任何包含@Scheduled方法的接口(带注释的@Component )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM