I am trying Spring 3's @Scheduled annotation . Here is my configuration (app.xml) :
// other beans
And this is my service class :
@Service public class ServiceImpl implements Service , Serializable { //other injections @Override @Transactional public void timeConsumingJob() { try { Thread.sleep(10*1000); } catch (InterruptedException e) { e.printStackTrace(); } } @Override @Scheduled(cron="* * * * * ?") public void secondly() { System.err.println("secondly : it is " + new Date()); } }
It works fine when testing in my eclispe + junit , when testing a timeConsumingJob method , I can see secondly() continues outputting message secondly.
But when deployed to a container (Resin/4.0.13) , it throws :
[11-03-26 12:10:14.834] {main} org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Only one AsyncAnnotationBeanPostProcessor may exist within the context. Offending resource: class path resource [app.xml] at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85) at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:72) at org.springframework.scheduling.config.AnnotationDrivenBeanDefinitionParser.parse(AnnotationDrivenBeanDefinitionParser.java:82)
I searched but seldom find similar situations , I think it is the most basic setting , but don't know why it doesn't work .
Can somebody take a look at it ? Thanks a lot !
(Spring 3.0.5 , Resin 4.0.13)
------------ updated ---------
After I dig deeper , I found the app.xml is imported by another xml. Maybe this is the reason makes task:annotation-driven
not working.
Well , after re-arranging some beans' location , it is solved, but I still feel puzzled. (Because it worked fine , and other.xml needs beans in app.xml )