resource 路径新建config。properties ,内容如下:
#each 5 second
repeat_time=0/5 * * * * ?
spring中,注明扫描包,和资源引用:
<context:component-scan base-package="com.sf.demo" />
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
</bean>
java中:
package com.sf.demo.server.manager.impl;
@Scheduled(cron="${repeat_time}")
public void doSomething() {
// something that should execute periodically
logger.info("schedule: begin............ ");
System.out.println("schedule z begin.............");
}