Passing a variable to annotation

0

I'm reading a JSON (using Jackson) and wanted to take this value and assign it to the Spring-Boot Annotation. It would be possible ? Here's the example below:

@Scheduled(fixedRate = 14400000)
    public void timelineUser() {
        log.info("Iniciando serviço da API de Tweets por usuário finalizado");
        TimeLineUserApi timeLineUserApi = new TimeLineUserApi();
        timeLineUserApi.run();
        log.info("Serviço da API de Tweets por usuário finalizado");
    }

I would like it to look like this:

@Scheduled(fixedRate = umavariavelqualquer) 
public void timelineUser() {
    log.info("Iniciando serviço da API de Tweets por usuário finalizado");
    TimeLineUserApi timeLineUserApi = new TimeLineUserApi();
    timeLineUserApi.run();
    log.info("Serviço da API de Tweets por usuário finalizado");
}

Thank you in advance for your understanding.

    
asked by anonymous 11.07.2016 / 23:06

1 answer

0

Hello, what you can do is use a variable that was declared in some configuration file (.yml, .propertiers) of spring, so it would look something like this:

@Scheduled(fixedDelayString = "${uma.propriedade.delay.seconds}")
public void timelineUser() {
    log.info("Iniciando serviço da API de Tweets por usuário finalizado");
    TimeLineUserApi timeLineUserApi = new TimeLineUserApi();
    timeLineUserApi.run();
    log.info("Serviço da API de Tweets por usuário finalizado");
}

If it was not very clear, you can ask me in the comments of the answer.

    
12.07.2016 / 05:02