I am using java 8 with spring boot
I have a class
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
class Sample{
@Scheduled(cron = "00 00 00 * * *")
public void print(){
System.out.println("Hello World!");
}
}
This method is will be invoked daily at 00:00:000 AM
Now for a time beeing I want to stop invoking that method.
One way we can comment the method.
Is there any better way to do that?
Like @Disabled
in junit.
CodePudding user response:
You can to use application.yml for feature flags in Spring Boot apps. This file usually defines the configuration of an application and simultaneously can be a perfect place for feature toggle. Based on a flag you can enable/disable the funcionality.
CodePudding user response:
Add condition on component like
@ConditionalOnProperty(name="schdularEnabled", value="true")
Then you can use application.yml with environment variables to toggle the shchedular