我尝试使用spring scheduler发送一封电子邮件,以便它每天早上9点和下午4点发送一封电子邮件,但我遇到的问题是调度程序将发送4封电子邮件当它执行工作时,而不是1。以下是我在spring配置文件中的内容:
<!-- Email Notification Job -->
<bean id="emailJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="name" value="emailNotification" />
<property name="group" value="notification" />
<property name="targetObject" ref="notificationService" />
<property name="targetMethod" value="createNotification" />
<property name="concurrent" value="false" />
</bean>
<!-- Email job description -->
<bean id="emailNotification" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="cronExpression" value="0 0 9,16 * * ?" /> <!-- Starts at 9am and 4pm everyday -->
<property name="jobDetail" ref="emailJobDetail" />
</bean>
<!-- Scheduler -->
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="emailNotification"/>
</list>
</property>
</bean>
因此,这将在spring服务'notificationService'中执行createNotification方法,该方法将向用户发送电子邮件。有没有人对这个问题有更好的了解?