@Scheduled注解中的值从配置文件中读取

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了@Scheduled注解中的值从配置文件中读取相关的知识,希望对你有一定的参考价值。

参考技术A 2020-03-04

1.例如:@Scheduled(cron = ("$0/6 * * * * ?"))corn表达式从配置文件中读取

解决方法:

         @PropertySource("classpath:properties/config.properties")

        public class TaskController

        //使spring能够识别 $cron

        //@Scheduled(cron = "0/5 * * * * ?")

            @Scheduled(cron ="$cron")

            public void testTask()

            System.out.println("设置的每6s执行一次。。。。。。。。");

               

            

cron=0/6 * * * * ?

以上是关于@Scheduled注解中的值从配置文件中读取的主要内容,如果未能解决你的问题,请参考以下文章