spring-bootgradleintellij-ideaspring-batchspring-batch-tasklet

In local, environment variable passed with IntelliJ is not working in spring boot batch


I am using Spring Boot Gradle plugin and developing in Intellij on Mac,

I'm trying to get value passed with environment variable but can not able to get it, (Passing 3 variables, among them only one systemDate is not able to access).

Environment variable settings in Intellij are as below. enter image description here

I had also tried to set it as a Override configuration properties in IntelliJ as below, enter image description here

Code where I am accessing it is as below.

String systemDate = Objects
        .toString(chunkContext.getStepContext().getJobParameters().get("systemDate"), "");

※Same code is working in staging environment. In staging I am passing systemDate like below,

java -Dspring.profiles.active=stg -Dspring.batch.job.names=abcPaymentJob -jar /var/lib/jenkins/deploy/stg/newAbcBatch.jar systemDate=2022-10-20T10:15:30

Solution

  • You are setting those key/value pairs as environment variables but you are trying to get them as job parameters here:

    chunkContext.getStepContext().getJobParameters()
    

    Job parameters and environment variables are two different things. You either need to: