Spring @Schedular在我的代码中执行两次

时间:2019-01-23 11:26:59

标签: java spring

我在下面给出了spring-dispatcher-servlet.xml的代码,它两次产生计划执行。我不知道为什么?

我的代码如下:

 <context:annotation-config />
    <context:component-scan base-package="app" />
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:resources mapping="/webjars/**"  location="/webjars/" />
    <mvc:annotation-driven />
    <task:annotation-driven />
    <tx:annotation-driven transaction-manager="transactionManager"/>
   <bean id="schedularController" class="app.controllers.schedularController" >


    <task:scheduled-tasks>
        <task:scheduled ref="schedularController" method="Scheduler" cron="${cron}" ></task:scheduled>
    </task:scheduled-tasks>

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean> 

并且在Java类中,代码类似于:

@Component
public class schedularController {

    private static final Logger LOGGER = Logger.getLogger(schedularController.class.getName());
    //Code For schedular
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    public void Scheduler(){            
            System.out.println("The time is now {}"+ dateFormat.format(new Date()));
}
}

output

0 个答案:

没有答案