Spring + Scheduled 动态读取配置文件内容
java代码
@Configuration
@EnableScheduling
@PropertySource(value = {"classpath:application.properties"})
public class TaskDemo{
/***************************************重要代碼部分*******************************/
//使spring能够识别 ${cron}
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev()
{return new PropertySourcesPlaceholderConfigurer();}
/***************************************重要代碼部分*******************************/
@Scheduled(cron ="${cron}") //从配置文件config.ini获取cron值
public void fun(){
System.out.println("任务执行");
}
}
配置文件
cron = 0/1 * * * * *