Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use a test override (e.g. testOverrides.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;!-- this file need to be imported before other contexts to ensure the test properties take effect --&gt; &lt;context:property-placeholder location="classpath*:META-INF/spring/testproperties/*.properties"/&gt; &lt;/beans&gt; </code></pre> <p>In your tests, make sure it's imported first:</p> <pre><code>@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath*:META-INF/spring/testOverrides.xml","classpath*:META-INF/spring/applicationContext.xml"}) public class SomeTest { ... } </code></pre> <p>Now put all your test properties in <code>src/test/resources/META-INF/spring/testproperties/</code>.</p> <p>You have to also make sure that the <code>main</code> placeholder configurer doesn't ever see <code>testproperties</code>, e.g. here's mine:</p> <pre><code>&lt;context:property-placeholder location="classpath*:META-INF/spring/*.properties"/&gt; </code></pre> <p>It doesn't use the double-* wildcard, so will only look at that one directory.</p> <p>I use the above method with great success.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload