title: How to make spring boot test app independent of external property source?
body: <p>I am writing a controller test for a spring boot application. To use the spring application context I am using SpringRunner class. <strong>The problem is the main application class has a property source defined to a specific file path</strong>.</p>
  <p>When I am running the test I am getting a FileNotFound exception from the hardcoded file. I want my test to be independent of this property source.</p>
  <p>I cannot add the 'ignoreResourceNotFound' option for property source in the main application.</p>
  <p>Below is the main application class with property source defined.</p>
  <pre><code>@SpringBootApplication
  @PropertySource(&quot;file:/opt/system/conf/smto/management.properties&quot;)
  @EnableConfigurationProperties
  public class ManagementApp {
  
      public static void main(String[] args) {
          SpringApplication.run(ManagementApp.class, args);
      }
  
  }
  </code></pre>
  <p>I am also adding my test class below</p>
  <pre><code>@RunWith(SpringRunner.class)
  @TestPropertySource(locations = {&quot;classpath:application.properties&quot;,&quot;classpath:management.properties&quot;})
  @DirtiesContext
  @EmbeddedKafka(topics = {&quot;management-dev&quot;},partitions = 1,
          controlledShutdown = false,brokerProperties = {&quot;listeners=PLAINTEXT://localhost:9092&quot;, &quot;port=9092&quot;})
  @AutoConfigureMockMvc
  @WebMvcTest(Controller.class)
  public class ControllerTest {
  }
  </code></pre>