我在这里很新,我不想诉诸问题,但似乎我别无选择。Spring with Maven:Maven没有找到我的资源
我正在写自动化测试,前一段时间我发现了Spring和Dependancy Injection及其所有优点。然后我用它在我的测试作为我的主要数据提供者(虽然我的一个同事用这种用法不同意,我不明白为什么),像这样:
/src/test/java/automation/data
上市:
@ContextConfiguration("classpath:/spring/surveyFlows.xml")
public class SurveyDataProvider
{
@Autowired
private List<Survey> allSurveys;
public List<Survey> getAllSurveys()
{
return allSurveys;
}
public SurveyDataProvider()
{
TestContextManager testContextManager = new TestContextManager(getClass());
try
{
testContextManager.prepareTestInstance(this);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
当然我的XML里面有 /src/test/resources/spring/
。
有趣的是,这工作得很好,如果我用的IntelliJ运行它,但maven
拒绝运行,给我那该死的错误:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring/surveyFlows.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/surveyFlows.xml] cannot be opened because it does not exist
我环顾四周小时所有的网络,试图各种各样的东西:
- 移动资源
/src/main
- 把资源目录中的
pom.xml
...没有骰子。
所以我有点卡在这里,我正在认真思考恢复到硬编码参数旧的Java风格。
如果有人有线索......
你可以在'target/test-classes/spring'下找到这个文件吗?你的pom是怎样的? – 2013-03-03 17:59:59
好吧,我看到在那里的xml,但它仍然无法正常工作 – jereshi 2013-03-04 08:18:43
我有同样的问题,并发现了一个类似的问题/答案,解决我的问题在这里:http://stackoverflow.com/questions/3571149/test-resources-的-依赖条件 - 非氟类路径 – kfox 2013-10-24 19:13:17