Why @Scheduled and <task:scheduled ../> behave differently for dependencies injection in Spring 3.1?
===

I need to schedule a task using Spring 3.1.
I'm using Roo's with ActiveRecord pattern for entities.

Method to be scheduled is very simple, in a dedicated service bean:

    public void sessionCleanup() {
        featureSessionManager.sessionCleanup();
    }

...configured as:

    <bean id="scheduledTaskService" class="it.blablabla.ScheduledTaskService">
        [...dependencies...]
    </bean>



If I schedule it using `@Scheduled(fixedRate=120000)` and enabling annotation-driven scheduling with `<task:annotation-driven/>` everything works as expected.



But if I want to schedule the same method using XML configuration...

    <task:scheduler id="scheduler" pool-size="1"/>
    <task:scheduled-tasks scheduler="scheduler" >
        <task:scheduled ref="scheduledTaskService" method="sessionCleanup" fixed-rate="120000"/>
    </task:scheduled-tasks>

...application throws an exception on initialization.


    2012-07-24 12:26:56,293 [pool-2-thread-1] INFO  org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler - Initializing ExecutorService  'scheduler'
    2012-07-24 12:26:56,671 [scheduler-1] ERROR org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.
    java.lang.IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)
    	at it.blablabla.model.AbstractFeatureSession_Roo_Jpa_ActiveRecord.entityManager_aroundBody0(AbstractFeatureSession_Roo_Jpa_ActiveRecord.aj:38)
    	at it.blablabla.model.AbstractFeatureSession_Roo_Jpa_ActiveRecord.ajc$interMethod$it.blablabla_model_AbstractFeatureSession_Roo_Jpa_ActiveRecord$it.blablabla_model_AbstractFeatureSession$entityManager(AbstractFeatureSession_Roo_Jpa_ActiveRecord.aj:1)
    	at it.blablabla.model.AbstractFeatureSession.entityManager(AbstractFeatureSession.java:1)
    	at it.blablabla.model.AbstractFeatureSession_Roo_Jpa_ActiveRecord.ajc$interMethodDispatch1$it.blablabla_model_AbstractFeatureSession_Roo_Jpa_ActiveRecord$it.blablabla_model_AbstractFeatureSession$entityManager(AbstractFeatureSession_Roo_Jpa_ActiveRecord.aj)
    	at it.blablabla.model.FeatureSession.updateAsDroppedAllExpiredAndNotDropped_aroundBody10(FeatureSession.java:245)
    	at it.blablabla.model.FeatureSession.updateAsDroppedAllExpiredAndNotDropped(FeatureSession.java:1)
    	at it.blablabla.service.FeatureSessionManagementServiceImpl.dropExpiredSessions(FeatureSessionManagementServiceImpl.java:154)
    	at it.blablabla.service.FeatureSessionManagementServiceImpl.sessionCleanup(FeatureSessionManagementServiceImpl.java:178)
    	at it.blablabla.task.ScheduledTaskWorker.sessionCleanup(ScheduledTaskWorker.java:37)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64)
    	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    	at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
    	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:662)

Apparently it fails to inject EntityManager into entities instantiated by the task.
(Roo's ActiveRecords are `@Configurable` and EntityManager is injected on instance creation) 

This happens either in Tomcat or in a JUnit.