I'm doing a Java application with Spring Boot and will receive a cron scheduler from docker-compose.yml. In NetBeans, I can read the values from application.yml, but when I deploy the image on docker server, I can't receive this params.
docker-compose.yml
integracao-spot:
container_name: integracao-spot
image: yuricolen13/integracaospot
restart: always
environment:
jobs_produto_cron: '0 40 9 * * *'
jobs_estoque_cron: '0 42 9 * * *'
jobs_vendas_cron: '0 44 9 * * *'
application.yml
jobs:
produto:
cron: '0 33 16 * * *'
estoque:
cron: '0 34 16 * * *'
vendas:
cron: '0 35 16 * * *'
EstoqueJob.class
@Component
@EnableScheduling
public class EstoqueJob {
public String diretorioLocal = "";
public String diretorioBucket = "cliente/indiana/indiana/diario/";
public String lojas = "(5,7,11,50,85)";
@Scheduled(cron = "${jobs.estoque.cron:-}")
public void estoqueJob() throws SQLException, IOException {
System.out.println("JOB SCHEDULED");
}
Read params from docker-compose.yml
Try with the following application.yml
jobs:
produto:
cron: ${jobs_produto_cron}
estoque:
cron: ${jobs_estoque_cron}
vendas:
cron: ${jobs_vendas_cron}
Keep in mind according to best practices for naming conventions, environmental variables have to be named with upercase letters. ex JOBS_PRODUTO_CRON
Also in your docker-compose.yml
you have to provide the values as list with -
.
...
environment:
- jobs_produto_cron: '0 40 9 * * *'
- jobs_estoque_cron: '0 42 9 * * *'
- jobs_vendas_cron: '0 44 9 * * *'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.