Spring Boot @Scheduled cron

前端 未结 2 1613
半阙折子戏
半阙折子戏 2020-12-16 00:17

Is there a way to call a getter (or even a variable) from a propertyClass in Spring\'s @Scheduled cron configuration? The following doesn\'t compil

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 00:59

    @Component
    public class MyReminder {
    
        @Autowired
        private SomeService someService;
    
        @Scheduled(cron = "${my.cron.expression}")
        public void excecute(){
            someService.someMethod();
        }
    }
    

    in /src/main/resources/application.properties

    my.cron.expression = 0 30 9 * * ?
    

提交回复
热议问题