I want to override properties defined in application.properties
through cmd with existing other in application.properties
, but @Scheduled
only allows to provide predefined values.
What I need is to pass the argument for @Scheduled
through command line which already exists in application.properties
and It will going to change the default value defined in @Scheduled
.
My question is that when I am executing jar file from cmd It is taking value present in @Scheduled
at the time of build. It is not overriding the existing value @Scheduled
value. I want to override value as per user need.
spring code
@SpringBootApplication
@EnableScheduling
public class PSchedularApplication {
public static void main(String[] args) {
for(String s : args)
System.out.println("arguments passed=>"+s);
SpringApplication application = new SpringApplication(PSchedularApplication .class);
if(!(args).equals(null))
{
application.setAddCommandLineProperties(true);
}
application.run(args);
}
}
@Component
public class TaskSchedular {
@Scheduled(cron="${cronExpression}")
public void taskScheduling()
{
System.out.println("Welcome to task schedular " + new java.util.Date());
moveFile();
}
}
Application.properties
cronExpression=0 0/1 * * * *
pzsc.poll.cron.weekly=0 0/2 * * * *
pzsc.poll.cron.daily=0/30 * * * * *
in cmd
java -jar PSchedular-0.0.1-SNAPSHOT.jar --cron=cronExpression