Passing a variable to Annotation

Asked

Viewed 129 times

0

I’m reading a JSON (using Jackson) and wanted to take that value and assign it to Spring-Boot Annotation. Would it be possible ? Follow 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’d like to keep it that way:

@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");
}

Thanks in advance for understanding.

1 answer

0

Hello, what you can do is use a variable that was declared in some spring configuration file(.yml, .propertiers), 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 is not very clear, you can ask me in the comments of the reply.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.