@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"/spring/spring-applicationContext.xml"}) public class PropertiesTest { @Value("${mail.163.username}") private String MAIL_163_USERNAME; @Test public void testPropertiesValues(){ System.out.println(MAIL_163_USERNAME); } }
說明:java
1.
spring
@ContextConfiguration(locations={"/spring/spring-applicationContext.xml"})
這裏locations裏的參數爲一個數組,能夠有多個參數,如@ContextConfiguration(locations={"/spring/spring-applicationContext.xml","spring-quarzt.xml","spring-activity"})數組
2.一樣locations的參數支持通配app
@ContextConfiguration(locations={"/spring/*-applicationContext.xml"})
code