Spring Quartz-Scheduler不断发出请求

时间:2012-01-19 13:09:48

标签: java spring quartz-scheduler

我有一个带有Quartz-Scheduler的Java Web应用程序,每天触发一次。但问题是他一次多次请求同一个触发器,有时它说有多个id为“cronTrigger”的实例。

Caused by: org.xml.sax.SAXParseException; lineNumber: 50; columnNumber: 90; cvc-id.2: There are multiple occurrences of ID value 'cronTrigger'.

我的意思是:

Trigger started .....
Trigger started .....
Trigger started .....
Trigger started .....

Trigger started .....
Trigger started .....
Trigger started .....
Trigger started .....

而不是:

Trigger started .....

Trigger started .....

Trigger started .....

Trigger started .....

Trigger started .....

我的applicationContext.xml如下所示:

<bean name="schedulerTask" class="com.myapp.struts.triggers.SchedulerTask"></bean>

<bean id="schedulerJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="schedulerTask" />
    <property name="targetMethod" value="execute" />
</bean>

<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="schedulerJob" />
    <property name="cronExpression" value="0/10 * * * * ?"/> //for test: scheduler is triggered each 10 seconds
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="cronTrigger"/>
        </list>
    </property>
</bean>

我无法找到问题的来源,也许你们可以帮助我......

1 个答案:

答案 0 :(得分:1)

我添加了新的applicationContext-scheduler.xml文件,然后将其添加到web.xml中:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/applicationContext.xml,
        /WEB-INF/applicationContext-scheduler.xml
    </param-value>
</context-param>

唯一运行良好的解决方案。