我有一個Spring項目。它適用於junit測試用例。 juint調用applicationcontext.xml並且項目成功運行。但我想在不使用jUnit的情況下運行該項目。 這裏是我的JUnit測試用例如何加載Spring應用程序上下文
package com.dataload;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.util.StopWatch;
@ContextConfiguration(locations = "classpath:com/dataload/applicationcontext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class SICSVDataTestCase {
private final static Logger logger = Logger
.getLogger(SICSVDataTestCase.class);
@Autowired
private JobLauncher launcher;
@Autowired
private Job job;
private JobParameters jobParameters = new JobParameters();
@Test
public void testLaunchJob() throws Exception {
StopWatch sw = new StopWatch();
sw.start();
launcher.run(job, jobParameters);
sw.stop();
logger.info(">>> TIME ELAPSED:" + sw.prettyPrint());
}
}
這測試用例運行項目。但是我想使用另一個可以調用applicationcontext.xml並運行該項目的類。
也就是說,
package com.dataload;
public class insertCSV
{
public static void main(String args[])
{
/* Code to run the project */
}
}
任何人都可以建議我如何編寫代碼?由於
謝謝。它的載入。但是當我運行測試用例時,我不需要調用其他類中的所有方法。它正在自動執行。但是在這裏只加載applicationcontext.xml。爲什麼會發生? – 2013-03-12 09:12:01
如果你的applicationContext有所有的bean被初始化,那麼這將工作正常。如果你想調用其他東西,你必須在加載應用程序上下文後手動執行。你希望你的主類表現如何? – Anubhab 2013-03-12 09:14:22
檢查編輯..我認爲這就是你需要的 – Anubhab 2013-03-12 09:16:42