Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable @Scheduled jobs by profile in spring?

How could I enabled scheduled jobs only in specific profiles?

pseudocode:

@Scheduled(cron = "${job.cron}")
@Profile("prod")
public void runJob() {

}

Is that possible?

like image 706
membersound Avatar asked Feb 28 '15 14:02

membersound


1 Answers

You should have one bean per profile:

@Component
@Profile("prod")
public class ProdJob {

    @Scheduled(cron = "${job.cron}")
    public void runJob() {

    }

}

@Component
@Profile("beta")
public class BetaJob {

    @Scheduled(cron = "${job.cron}")
    public void runJob() {

    }
}
like image 131
fps Avatar answered Oct 06 '22 22:10

fps