How to read generated properties file in Spring Boot integration test?
<p>In a Spring Boot web application, I use the <code>git-commit-id-plugin</code> Maven plugin to generate a file named <code>git.properties</code>, containing all the git commit information, e.g:</p>

<pre><code>git.commit.id=35ca97298544d4ee6f8a5392211ebaa0d9bdafeb
</code></pre>

<p>This file is generated  directly in the <code>target/classes</code> repository. So it's included in the classpath. At runtime the file is loaded via an annotation on my main application class :</p>

<pre><code>@PropertySource({"git.properties"})
</code></pre>

<p>I can then use expressions in my beans to get the value of the properties contained in the <code>git.properties</code> file :</p>

<pre><code>@Value("${git.commit.id}")
private String gitCommitIdFull; // will contain "35ca97298544d4ee6f8a5392211ebaa0d9bdafeb"
</code></pre>

<p>It all works very well when running the app normally.</p>

<p>But I am now trying to run some integration tests that are run with :</p>

<pre><code>@RunWith(SpringRunner.class)
@SpringBootTest
public class SampleSearchDAOTest {
    //tests here...
}
</code></pre>

<p>I get the following exception :</p>

<pre><code>java.lang.IllegalStateException: Failed to load ApplicationContext
(...)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException:
Failed to parse configuration class [ch.cscf.mds.MdsApiApplication]; 
nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/git.properties]
</code></pre>

<p>Obviously, the way the tests are run, they seem to not use <code>target/classes</code> as the base for the classpath.</p>

<p>What does it use ? How can I make the runtime for these tests aware of the <code>target/classes/git.properties</code> file ?</p>

<p>I tried to generate the <code>git.properties</code> file into the <code>src/main/resources</code> directory instead of the <code>target/classes</code> repository. I still have the same error.</p>