Using properties files in spring-boot tests
<p>I have simple spring boot web service, where for configuration I use <code>.properties</code> files. As example for spring-mail configuration, I have separate file <code>mailing.properties</code> located in <code>src/main/resources/config/</code> folder.</p>

<p>in main application I include it using:</p>

<pre><code>@PropertySource(value = { "config/mailing.properties" })
</code></pre>

<p>The problem appears when it comes to tests, I would like to use the same properties from this file, but when i try to use it, I get <code>fileNotFaundExeption</code>. </p>

<p>Question is: </p>

<ul>
<li>Should I have separate resources in my <code>src/test</code> folder, or it is possible to access resources from <code>src/main</code> folder, if yes, how?</li>
</ul>

<p><strong>UPDATE added sources</strong></p>

<p>test class:</p>

<pre><code>    @RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource("classpath:config/mailing.properties")
public class DemoApplicationTests {

    @Autowired
    private TestService testService;

    @Test
    public void contextLoads() {
        testService.printing();
    }

}
</code></pre>

<p>service class:</p>

<pre><code>    @Service
public class TestService
{
    @Value("${str.pt}")
    private int pt;

    public void printing()
    {
        System.out.println(pt);
    }
}
</code></pre>

<p>main app class:</p>

<pre><code>@SpringBootApplication
@PropertySource(value = { "config/mailing.properties" })
public class DemoApplication {

    public static void main(String[] args)
    {
        SpringApplication.run(DemoApplication.class, args);
    }
}
</code></pre>

<p><a href="https://i.stack.imgur.com/1pBPR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1pBPR.jpg" alt="structure"></a></p>