Junit手動/自動加載spring配置文件


分配置文件在classpath下和web-inf下兩種情況的加載: 

ApplicationContext context = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/applicationContext.xml"); 
new ClassPathXmlApplicationContext("applicationContext.xml");// 從classpath中加載 
new FileSystemXmlApplicationContext("classpath:地址");// 沒有classpath表示當前目錄 

  




注解加載 

@org.springframework.test.context.ContextConfiguration(locations={"file:WebRoot/WEB-INF/applicationContext.xml"}) 

@org.springframework.test.context.ContextConfiguration(locations={"classpath:applicationContext.xml"}) 

  

 

@RunWith(SpringJUnit4ClassRunner.class)  
@ContextConfiguration({"classpath:/ut/applicationContext.xml"}) 
public class ScanDecisionFileTest {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testRun() {
		//fail("Not yet implemented");
	}

}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM