title: Docker cannot find Resource on classpath
body: <p>I have a simple gradle spring boot java application, where I am trying to get some properties value from  "application.properties" and "application-dev.properties" using spring boot profiling. It is working fine and spring boot profile is loading when I try to run application on the local machine, but when when I try to run same application on the docker, so suddenly error popsup which says that application is not able to find resources on the classpath.</p>
  
  <p>Below is the project structure</p>
  
  <p><a href="https://i.stack.imgur.com/4bm3I.png" rel="noreferrer"><img src="https://i.stack.imgur.com/4bm3I.png" alt="Project structure of the application"></a></p>
  
  <p>In the App.Config class I have the following code. As you can see I am trying to get property value from application.properties file.</p>
  
  <pre><code>@Component
  @PropertySource("classpath:application.properties")
  public class AppConfig {
  
  @Value("${host}")
  private String host;
  @Value("${map}")
  private String map;
  
  public String getHost() {
      return host;
  }
  
  public void setHost(String host) {
      this.host = host;
  }
  
  public String getMap() {
      return map;
  }
  
  public void setMap(String map) {
      this.map = map;
  }
  }
  </code></pre>
  
  <h2>application.properties contains following code.</h2>
  
  <pre><code>map = Main-Map
  
  spring.profiles.active=${profile}
  </code></pre>
  
  <h2>application-dev.properties contains following code</h2>
  
  <pre><code>host = Development-host
  </code></pre>
  
  <p>As you can see I am setting profile value in application.properties from outside. Thats what I am trying to inject through docker</p>
  
  <h2>Dockerfile contain following code</h2>
  
  <pre><code>FROM java:8
  
  VOLUME /tmp
  
  ENV tom=dev
  
  ADD build/libs/demo-0.0.1-SNAPSHOT.jar /app/app.jar
  
  ADD build/resources/main/application.properties /app/application.properties
  
  ADD build/resources/main/application-dev.properties /app/application-dev.properties
  
  WORKDIR /app
  
  ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","- 
  Dprofile=${tom}","-jar","app.jar", "- 
  -spring.config.location=/app/application.properties, /app/application- 
  dev.properties"]
  </code></pre>
  
  <h2>I build docker image using following command</h2>
  
  <pre><code>docker build -t demo:latest .
  </code></pre>
  
  <h2>I run docker using following command</h2>
  
  <pre><code>docker run -p 8083:8080 demo:latest
  </code></pre>
  
  <h2>When I run docker run command, so comes below exception.</h2>
  
  <pre><code>2019-12-12 07:09:50.405  INFO 1 --- [           main] com.example.demo.DemoApplication         : 
  Starting DemoApplication on ed7cb11b8a34 with PID 1 (/app/app.jar started by root in /app)
  2019-12-12 07:09:50.407  INFO 1 --- [           main] com.example.demo.DemoApplication         : The 
  following profiles are active: dev
  2019-12-12 07:09:50.603  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : 
  Exception encountered during context initialization - cancelling refresh attempt: 
  org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class 
  [com.example.demo.DemoApplication]; nested exception is java.io.FileNotFoundException: class path 
  resource [application.properties] cannot be opened because it does not exist
  2019-12-12 07:09:50.712 ERROR 1 --- [           main] o.s.boot.SpringApplication               : 
  Application run failed
  
  org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [   com.example.demo.DemoApplication]; nested exception is java.io.FileNotFoundException: class path 
  resource [ application.properties] cannot be opened because it does not exist
      at 
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks in advance.</p>