Spring3の@Scheduledアノテーションを試しています。これが私の設定(app.xml)です:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
"
>
<context:component-scan base-package="destiny.web"/>
<context:annotation-config/>
// other beans
<task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>
<task:executor id="myExecutor" pool-size="5"/>
<task:scheduler id="myScheduler" pool-size="10"/>
</beans>
そしてこれは私のサービスクラスです:
@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());
}
}
eclispe + junitでテストする場合は正常に機能し、timeConsumingJobメソッドをテストする場合は、secondly()が2番目にメッセージを出力し続けることがわかります。
しかし、コンテナ(Resin / 4.0.13)にデプロイすると、次のようにスローされます。
[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)
検索しましたが、似たような状況はめったに見つかりませんでした。これが最も基本的な設定だと思いますが、なぜ機能しないのかわかりません。
誰かがそれを見ることができますか?どうもありがとう !
(Spring 3.0.5、Resin 4.0.13)
------------更新---------
深く掘り下げてみると、app.xmlが別のxmlによってインポートされていることがわかりました。たぶんこれが機能しない理由task:annotation-driven
です。
さて、いくつかの豆の場所を再配置した後、それは解決されましたが、それでも私は戸惑いを感じます。(正常に機能し、other.xmlにはapp.xmlにBeanが必要なため)