0

我尝试使用 spring 调度程序发送一封电子邮件,以便它每天在上午 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 方法,该方法将向用户发送电子邮件。有没有人对这个问题有更好的理解?

4

0 回答 0