Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-7216

@Scheduled processed twice when accidentally using @Configurable on a managed bean

    Details

    • Type: Task
    • Status: Closed
    • Priority: Trivial
    • Resolution: Complete
    • Affects Version/s: 3.0.2
    • Fix Version/s: 3.0.3
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Here is a stack trace of a @Scheduled annotation being added to cronTasks:

      Thread [main] (Suspended (breakpoint at line 117 in ScheduledAnnotationBeanPostProcessor$1))
      ScheduledAnnotationBeanPostProcessor$1.doWith(Method) line: 117
      ReflectionUtils.doWithMethods(Class<?>, MethodCallback, MethodFilter) line: 455
      ReflectionUtils.doWithMethods(Class<?>, MethodCallback) line: 431
      ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(Object, String) line: 90
      DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).applyBeanPostProcessorsAfterInitialization(Object, String) line: 407
      DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initializeBean(String, Object, RootBeanDefinition) line: 1418
      DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initializeBean(Object, String) line: 386
      BeanConfigurerSupport.configureBean(Object) line: 141
      AnnotationBeanConfigurerAspect.configureBean(Object) line: 59
      AnnotationBeanConfigurerAspect(AbstractDependencyInjectionAspect).ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(Object) line: 89
      <unknown receiving type>(XxxJob).<init>() line: 69
      NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]
      NativeConstructorAccessorImpl.newInstance(Object[]) line: 39
      DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 27
      Constructor<T>.newInstance(Object...) line: 513
      BeanUtils.instantiateClass(Constructor<T>, Object...) line: 126
      CglibSubclassingInstantiationStrategy(SimpleInstantiationStrategy).instantiate(RootBeanDefinition, String, BeanFactory) line: 72
      DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).instantiateBean(String, RootBeanDefinition) line: 948
      DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBeanInstance(String, RootBeanDefinition, Object[]) line: 901
      DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 485
      DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 456
      AbstractBeanFactory$1.getObject() line: 291
      DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory) line: 222
      DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 288
      DefaultListableBeanFactory(AbstractBeanFactory).getBean(String) line: 190
      DefaultListableBeanFactory.preInstantiateSingletons() line: 563
      XmlWebApplicationContext(AbstractApplicationContext).finishBeanFactoryInitialization(ConfigurableListableBeanFactory) line: 872
      XmlWebApplicationContext(AbstractApplicationContext).refresh() line: 423
      ContextLoaderListener(ContextLoader).createWebApplicationContext(ServletContext, ApplicationContext) line: 276
      ContextLoaderListener(ContextLoader).initWebApplicationContext(ServletContext) line: 197
      ContextLoaderListener.contextInitialized(ServletContextEvent) line: 47
      StandardContext.listenerStart() line: 3972
      StandardContext.start() line: 4467
      StandardHost(ContainerBase).start() line: 1045
      StandardHost.start() line: 785
      StandardEngine(ContainerBase).start() line: 1045
      StandardEngine.start() line: 443
      StandardService.start() line: 519
      StandardServer.start() line: 710
      Catalina.start() line: 581
      NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
      NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
      DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
      Method.invoke(Object, Object...) line: 597
      Bootstrap.start() line: 289
      Bootstrap.main(String[]) line: 414

      Shortly thereafter, the same annotation on the same bean instance is processed a second time from doCreateBean, the same method. Here is the diff of the first and second stack traces:

      — stack1 2010-05-19 01:56:49.000000000 -0500
      +++ stack2 2010-05-19 01:56:46.000000000 -0500
      @@ -5,20 +5,7 @@
      ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(Object, String) line: 90
      DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).applyBeanPostProcessorsAfterInitialization(Object, String) line: 407
      DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initializeBean(String, Object, RootBeanDefinition) line: 1418

      • DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initializeBean(Object, String) line: 386
      • BeanConfigurerSupport.configureBean(Object) line: 141
      • AnnotationBeanConfigurerAspect.configureBean(Object) line: 59
      • AnnotationBeanConfigurerAspect(AbstractDependencyInjectionAspect).ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(Object) line: 89
      • <unknown receiving type>(ClientSavingsPlanJob).<init>() line: 69
      • NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]
      • NativeConstructorAccessorImpl.newInstance(Object[]) line: 39
      • DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 27
      • Constructor<T>.newInstance(Object...) line: 513
      • BeanUtils.instantiateClass(Constructor<T>, Object...) line: 126
      • CglibSubclassingInstantiationStrategy(SimpleInstantiationStrategy).instantiate(RootBeanDefinition, String, BeanFactory) line: 72
      • DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).instantiateBean(String, RootBeanDefinition) line: 948
      • DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBeanInstance(String, RootBeanDefinition, Object[]) line: 901
      • DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 485
        + DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 519
        DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 456
        AbstractBeanFactory$1.getObject() line: 291
        DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory) line: 222

      This only seems to affect two beans that I use with Spring Batch, although that may not actually matter. Both job beans are annotated at the class level with @Service and @Configurable(dependencyCheck = true), both extend the same abstract subclass with @Autowired annotations on fields, and both @Scheduled annotations are on methods with @Transactional.

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              cgs Christopher G. Stach II
              Last updater:
              Trevor Marshall
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                7 years, 46 weeks, 6 days ago