0

Scheduler not working when reading values from yaml file

application.yaml file content is
enode:
  enable: Y
  timer: 10 * * * * *

java file that reads above element from yaml file.

@Component
@ConfigurationProperties("enode")
public class EnodeConfigs {
    private String enable;
    private String timer;

controller code with scheduler


@Component
public class EnodeController {


    @Autowired
    private EnodeConfigs e;


    @Bean
    public String getTimer() {
        return e.getTimer();
    }

    @Scheduled(cron = "#{@getTimer}")
    public void delEnodeFiles() {
       System.out.println("hello");

    }

    @Scheduled(cron = "10 * * * * *")
    public void test() {
        System.out.println("hii");

        System.out.println(getTimer());

    }

test method works as expected and it prints getTimer() value too. but delEnodeFiles() method not working. Quick help please. Thanks.

user7220859
  • 113
  • 2
  • 2
  • 9
  • Probably a duplication of https://stackoverflow.com/questions/36204858/spring-boot-scheduled-cron although there is a way to grab the cron expression directly from properties specified in the question itself that still can be an answer to this question – Mark Bramnik Feb 10 '20 at 14:33
  • Please don't do it like that. Don't use a SpEL expression, just use a value expression `${enode.timer}` as the expression. It will not evaluate a SpEL expression. – M. Deinum Feb 10 '20 at 14:33
  • I have used ${enode.timer} too but not working. Is there anything I am missing? – user7220859 Feb 11 '20 at 06:05

0 Answers0