Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't Spring running my @Scheduled method?
    primarykey
    data
    text
    <p>I'm a bit befuddled because I'm trying use use <code>@Scheduled</code> annotations, but Spring doesn't seem to be finding my methods. The end result is that, none of my methods annotated with <code>@Scheduled</code> are being executed.</p> <p>I have invoked Spring's task magic with the following declarations:</p> <pre><code>&lt;beans&gt; &lt;!-- XMLNS, XSD declarations omitted for brevity --&gt; &lt;context:component-scan base-package="com.mypackage"/&gt; &lt;task:executor id="executor" pool-size="5"/&gt; &lt;task:scheduler id="scheduler" pool-size="5"/&gt; &lt;task:annotation-driven scheduler="scheduler" executor="executor"/&gt; &lt;/beans&gt; </code></pre> <p>And I have an interface that looks something like this:</p> <pre><code>package com.mypackage; public interface MyInterface { public void executePeriodically(); } </code></pre> <p>With a corresponding impl like this:</p> <pre><code>package com.mypackage.impl; // imports omitted for brevity @Service public class MyInterfaceImpl implements MyInterface { @Scheduled(cron = "0/5 * * * * ?") public void executePeriodically() { System.out.println("The time is now : " + new Date()); } } </code></pre> <p>Now the expected result is that I have a very noisy little guy telling me what time it is every 5 seconds...but in reality I get absolutely nothing. I've tried with the annotation on the interface method and on the impl method, but that doesn't seem to change anything.</p> <p>I know for sure that the executor and scheduler are being initialized because I have the following in my log:</p> <pre><code>INFO - ThreadPoolTaskExecutor - Initializing ExecutorService INFO - XmlWebApplicationContext - Bean 'executor' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) INFO - XmlWebApplicationContext - Bean 'executor' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) INFO - ThreadPoolTaskScheduler - Initializing ExecutorService 'scheduler' INFO - XmlWebApplicationContext - Bean 'scheduler' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) </code></pre> <p>I'm not sure if that line about not being eligible is relevant or a red herring.</p> <p>At the moment, I'm working around it by declaring my scheduled tasks like so:</p> <pre><code>&lt;task:scheduled-tasks&gt; &lt;task:scheduled ref="sourceDocumentManagerImpl" method="deleteOldDocuments" cron="0 0 * * * ?"/&gt; &lt;/task:scheduled-tasks&gt; </code></pre> <p>While this works perfectly fine, I'd much rather use the annotations because it's so much more convenient to see directly in the code what the expectations are for that method. Anyone know what I could be doing wrong? For the record, I'm using Spring 3.0.4</p> <p>Thanks a bunch!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload