Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change cron expression of spring scheduler from properties file without restarting tomcat server?

I am using spring scheduler.This works fine but when I changed cron.expression value in application.properties every time I need to restart tomcat server.Is there any way that I can make it dynamic like automatically changes will reflect ? I did google also but didnt got any solution for my app.I have given code snippet as follows:

application.properties

cron.expression=0 58 23 * * ?

@Scheduled(cron = "${cron.expression}", zone = "IST")
public void sendEmail() throws Exception {



}
like image 381
Tejal Avatar asked Oct 27 '17 08:10

Tejal


1 Answers

It's an easy task if you are working on spring-cloud. Spring has a project called 'spring cloud config' which helps you to achieve the externalize the properties and whenever there is a change, that change will push to your service. Have a look at setting up spring cloud config

You may find many samples for same. Let me know if you are looking for code.

like image 119
Vivek Shukla Avatar answered Sep 20 '22 12:09

Vivek Shukla