美文网首页
注解方式使用Spring定时任务

注解方式使用Spring定时任务

作者: Franck_ | 来源:发表于2020-03-04 13:08 被阅读0次

    spring cron expression must consist of 6 fields 。

    @Scheduled(cron = "${corn.newChatOrderCheck}")

    使用这个注解来定义cron表达式。需要在配置文件里面配置,达到动态读取的效果。

    1 在类最前面加配置文件的读取路径。
    @PropertySource("classpath:application.properties")

    2 在类里面添加以下代码。其实是一个Bean (作用还要继续研究)

       @Bean
        public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
            return new PropertySourcesPlaceholderConfigurer();
        }
    

    3 在配置文件里面添加

    corn.newChatOrderCheck
    

    相关文章

      网友评论

          本文标题:注解方式使用Spring定时任务

          本文链接:https://www.haomeiwen.com/subject/bnoixhtx.html