title: Pass Docker arguments to Spring boot properties
body: <p>In a project locally that I've created to test passing Docker arguments to my spring boot <code>application.properties</code> I have in the <code>application.properties</code>: <code>test.name=${name}</code></p>
  
  <p>and in the application </p>
  
  <pre><code>@SpringBootApplication
  public class RestServiceApplication {
  
      @Value("${test.name}")
      private String test;
  
      public static void main(String[] args) {
          SpringApplication.run(RestServiceApplication.class, args);
      }
  
      @Bean(name = "test")
      public String getTest() {
          return this.test;
      }
  }
  </code></pre>
  
  <p>My Dockerfile:</p>
  
  <pre><code>FROM openjdk:8-jdk-alpine
  ARG NAME
  ENV TEST_NAME=${NAME}
  RUN echo $TEST_NAME
  ARG JAR_FILE=target/*.jar
  RUN echo JAR_FILE
  ADD ${JAR_FILE} app.jar
  ENTRYPOINT ["java","-jar","/app.jar"]
  </code></pre>
  
  <p>Building it with <code>sudo docker build -t gs-rest-service --build-arg NAME=Alex .</code> This works fine locally</p>
  
  <p>Now on a different project my <code>application.properties</code>:</p>
  
  <pre><code>bulk.api.username=${BULK_USERNAME}
  bulk.api.password=${BULK_PASSWORD}
  </code></pre>
  
  <p>and my Dockerfile:</p>
  
  <pre><code>FROM maven:3.6.0-jdk-8 AS build
  
  ARG ARTIFACTORY_USER
  ARG ARTIFACTORY_PASSWORD
  
  WORKDIR /build
  COPY . .
  
  RUN mvn -s settings.xml clean package
  
  ARG BULK_USERNAME
  ARG BULK_PASSWORD
  ENV BULK_API_USERNAME=${BULK_USERNAME}
  ENV BULK_API_PASSWORD=${BULK_PASSWORD}
  RUN echo $BULK_API_PASSWORD
  
  FROM openjdk:8-jre-alpine
  
  WORKDIR /opt/cd-graph-import
  COPY --from=build /build/target/abc-svc.jar .
  
  ENTRYPOINT ["java", "-jar", "abc-svc.jar"]
  </code></pre>
  
  <p>My spring boot class:</p>
  
  <pre><code>@SpringBootApplication
  public class SpringBootApplication {
  
      @Value("${bulk.api.username}")
      private String bulkApiUsername;
  
      @Value("${bulk.api.password}")
      private String bulkApiPassword;
  
      public static void main(String[] args) {
          SpringApplication.run(SpringBootApplication.class, args);
      }
  
      @Bean
      public RestTemplate restTemplate() {
          return new RestTemplateBuilder().basicAuthentication(bulkApiUsername, bulkApiPassword).build();
      }
  
      @Bean(name = "bulkApiUrl")
      public String getBulkApiUrl() {
          return this.bulkApiUrl;
      }
  }
  </code></pre>
  
  <p>When this runs in gitlab with:</p>
  
  <pre><code>docker build -t $SERVICE_IMAGE --build-arg ARTIFACTORY_USER=$ARTIFACTORY_USER --build-arg ARTIFACTORY_PASSWORD=$ARTIFACTORY_PASSWORD --build-arg BULK_USERNAME=$BULKAPI_USERNAME --build-arg BULK_PASSWORD=$BULKAPI_PASSWORD .
  </code></pre>
  
  <p>I see that <code>$BULK_API_PASSWORD</code> is set properly but when running the application I get the error: `Error creating bean with name </p>
  
  <pre><code>'someApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'BULK_USERNAME' in value "${BULK_USERNAME}"
  </code></pre>
  
  <p>What am I missing?</p>