title: Spring Boot app: Could not resolve placeholder in application.properties?
body: <p>I have a spring boot app. It works when fine when I click "run" button in SpringToolSuit4. </p>
  
  <p>But when I run as "maven install", I got the error message: </p>
  
  <pre><code>&lt;error message="Failed to load ApplicationContext" type="java.lang.IllegalStateException"&gt;java.lang.IllegalStateException: Failed to load ApplicationContext
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'envVersionNum' in value "${envVersionNum}"
  Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'envVersionNum' in value "${envVersionNum}"
  &lt;/error&gt;
  </code></pre>
  
  <p>The content of my application properties:</p>
  
  <pre><code>spring.h2.console.enabled=true
  spring.h2.console.path=/h2-console
  spring.jpa.show-sql=true
  spring.thymeleaf.cache=false
  version=${envVersionNum}
  </code></pre>
  
  <p>If I change it to </p>
  
  <pre><code>spring.h2.console.enabled=true
  spring.h2.console.path=/h2-console
  spring.jpa.show-sql=true
  spring.thymeleaf.cache=false
  version=1.1.1
  </code></pre>
  
  <p>It works fine. But I want to get the envVersionNum from user, which is stored in .bash_profile (export envVersionNum= 1.1.1).</p>
  
  <p>the content of pom.xml:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.2.1.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.jrp&lt;/groupId&gt;
      &lt;artifactId&gt;project-management&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;project-management&lt;/name&gt;
      &lt;description&gt;project management application&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                      &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p>The code of homeController:</p>
  
  <pre><code>package com.jrp.pma.controllers;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.GetMapping;
  
  import com.fasterxml.jackson.core.JsonProcessingException;
  import com.fasterxml.jackson.databind.ObjectMapper;
  import com.jrp.pma.dao.EmployeeRepository;
  import com.jrp.pma.dao.ProjectRepository;
  import com.jrp.pma.dto.ChartData;
  import com.jrp.pma.dto.EmployeeProject;
  import com.jrp.pma.entities.Project;
  
  @Controller
  public class HomeController {
  
      @Value("${version}")
      private String ver;
  
      @Autowired
      ProjectRepository proRepo;
  
      @Autowired
      EmployeeRepository empRepo;
  
      @GetMapping("/")
      public String displayHome(Model model) throws JsonProcessingException {
  
          model.addAttribute("versionNumber", ver);
  
          Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
  
          // we are querying the database for projects
          List&lt;Project&gt; projects = proRepo.findAll();
          model.addAttribute("projectsList", projects);
  
          List&lt;ChartData&gt; projectData = proRepo.getProjectStatus();
  
          // Lets convert projectData object into a json structure for use in javascript
          ObjectMapper objectMapper = new ObjectMapper();
          String jsonString = objectMapper.writeValueAsString(projectData);
          //[["NOTSTARTED", 1], ["INPROGRESS", 2], ["COMPLETED", 1]]
          model.addAttribute("projectStatusCnt", jsonString);
  
          // we are querying the database for employees
          List&lt;EmployeeProject&gt; employeesProjectCnt = empRepo.employeeProjects();
          model.addAttribute("employeesListProjectsCnt", employeesProjectCnt);
  
          return "main/home";
      }
  }
  </code></pre>
  
  <p>Any suggestions gratefully accepted.</p>