title: Spring boot: maven package with specific profile
body: <p>The goal is, to have <code>dev</code> and <code>prod</code> environments. For the local run to use <code>application-dev.yml</code> and for deploying to the server to use <code>application-prod.yml</code></p>
  
  <p>I have 3 configuration files</p>
  
  <p><strong>application.yml</strong></p>
  
  <pre><code>spring:
    main:
      banner-mode: off
  </code></pre>
  
  <p><strong>application-dev.yml</strong></p>
  
  <pre><code>spring:
    datasource:
      password: dev-user-pwd
      username: dev-user
      url: jdbc:mysql://localhost:3306/db
      driver-class-name: com.mysql.cj.jdbc.Driver
  </code></pre>
  
  <p><strong>application-prod.yml</strong></p>
  
  <pre><code>spring:
    datasource:
      password: prod-user-pwd
      username: prod-user
      url: jdbc:mysql://localhost:3306/db
      driver-class-name: com.mysql.cj.jdbc.Driver
  </code></pre>
  
  <p>In the server, I have <code>maven</code> installed and trying to run</p>
  
  <pre><code>mvn clean package -Dspring.profiles.active=prod
  </code></pre>
  
  <p>Here is the error log that I'm getting </p>
  
  <pre><code>Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.966 s &lt;&lt;&lt; FAILURE! - in com.partplug.api.ApiApplicationTests
  contextLoads  Time elapsed: 0.005 s  &lt;&lt;&lt; ERROR!
  java.lang.IllegalStateException: Failed to load ApplicationContext
  Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.web.config.SpringDataWebConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.NoClassDefFoundError: org/xmlbeam/config/XMLFactoriesConfig
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.web.config.SpringDataWebConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.NoClassDefFoundError: org/xmlbeam/config/XMLFactoriesConfig
  Caused by: java.lang.NoClassDefFoundError: org/xmlbeam/config/XMLFactoriesConfig
  Caused by: java.lang.ClassNotFoundException: org.xmlbeam.config.XMLFactoriesConfig
  </code></pre>
  
  <p><strong>In short:</strong> the error says that, datasource and all sub-properties are not defined. Meaning, maven packager doesn't change the active profile to prod.</p>
  
  <p>What am I doing wrong?</p>