title: Spring Boot: @TestConfiguration Not Overriding Bean During Integration Test
body: <p>I have a <code>Bean</code> defined in a class decorated with <code>@Configuration</code>:</p>
  <pre><code>@Configuration
  public class MyBeanConfig {
      @Bean
      public String configPath() {
          return &quot;../production/environment/path&quot;;
      }
  }
  </code></pre>
  <p>I have a class decorated with <code>@TestConfiguration</code> that should override this <code>Bean</code>:</p>
  <pre><code>@TestConfiguration
  public class MyTestConfiguration {
      @Bean
      @Primary
      public String configPath() {
          return &quot;/test/environment/path&quot;;
      }
  }
  </code></pre>
  <p>The <code>configPath</code> bean is used to set the path to an external file containing a registration code that must be read during startup. It is used in an <code>@Component</code> class:</p>
  <pre><code>@Component
  public class MyParsingComponent {
      private String CONFIG_PATH;
      
      @Autowired
      public void setCONFIG_PATH(String configPath) {
          this.CONFIG_PATH = configPath;
      }
  }
  </code></pre>
  <p>While trying to debug this I set a breakpoint inside each method as well as the constructor of the test config class. The <code>@TestConfiguration</code>'s constructor breakpoint is hit, so i know that my test configuration class instantiates, however the <code>configPath</code> method of that class is never hit. Instead, the <code>configPath</code> method of the normal <code>@Configuration</code> class is hit and the <code>@Autowired</code> <code>String</code> in <code>MyParsingComponent</code> is always <code>../production/environment/path</code> rather than the expected <code>/test/environment/path</code>.</p>
  <p>Not sure why this is happening. Any thoughts would be greatly appreciated.</p>