I’d like a task to run every 10 seconds. When I declare the Bean in my applicationContext.xml file, everything works as expected. When I simply annotate the Bean with @Component, the task never executes. My code/config looks like the following:
QueueProcessor.scala
package example.components
// imports removed for brevity
@Component
class QueueProcessor {
@Scheduled(fixedDelay = 10000)
def poll() = {
println("polling queue")
}
}
applicationContext.xml
<context:component-scan base-package="example.components" />
<task:executor id="genericExecutor" pool-size="2" />
<task:scheduler id="genericScheduler" pool-size="2" />
<task:annotation-driven executor="genericExecutor" scheduler="genericScheduler" />
If I simply add a line with <bean id="queueProcessor" class="example.components.QueueProcessor" />, to my applicationContext.xml, then the task executes every 10 seconds as expected. I’ve verified that other classes in the example.components package are being instantiated via annotation, so this class not being discovered shouldn’t be the issue.
Any ideas as to what else might be wrong?
EDIT: I moved the line <task:annotation-driven executor="genericExecutor" scheduler="genericScheduler" /> to my servlet.xml file. That solved the problem. Does this have to do with the order in which the files are read?
As noted in the edited question, moving the line
<task:annotation-driven executor="genericExecutor" scheduler="genericScheduler" />to theservlet.xmlfile resolved the issue.