eine Testüberschreibung (z testOverrides.xml) Verwendung:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!-- this file need to be imported before other contexts to ensure the test properties take effect -->
<context:property-placeholder location="classpath*:META-INF/spring/testproperties/*.properties"/>
</beans>
In Ihren Tests, stellen Sie sicher, dass es zuerst importiert:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:META-INF/spring/testOverrides.xml","classpath*:META-INF/spring/applicationContext.xml"})
public class SomeTest { ... }
nun Ihre Test alle Eigenschaften in src/test/resources/META-INF/spring/testproperties/
setzen.
Sie müssen auch sicherstellen, dass der main
Platzhalter configurer je testproperties
, zum Beispiel nicht sehen hier ist meins:
<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
Es verwendet nicht die Doppel-* Wildcard, so wird nur auf dieses ein Verzeichnis zu sehen.
Ich benutze die oben genannte Methode mit großem Erfolg.
Es tut dies automatisch. Wie liest du sie? – Bozho
ich die Eigenschaftendatei im Anwendungskontext xml lesen mit \t \t \t –