我有一个Java项目,我正在编写一个简单的JUNIT测试用例。我已将applicatinoContext.xml文件复制到根java源目录中。我已经尝试了一些推荐的设置,我已经读过这里的StackOverflow,但仍然得到相同的错误。是因为我的项目是一个java项目而不是一个Web项目,是否发生这种错误,或者甚至是重要的?我不知道哪里错了。
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"C:/projs/sortation/src/main/java/applicationContext.xml"})
// Also tried these settings but they also didnt work,
//@ContextConfiguration(locations={"classpath:applicationContext.xml"})
//@ContextConfiguration("classpath:applicationContext.xml")
@Transactional
public class TestSS {
@Autowired
private EmsDao dao;
@Test
public void getSites() {
List batchid = dao.getList();
for (String s : batchid) {
System.out.println(s);
}
}
}