站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2EE 专题使用spring的unit test,找不到配置文件

使用spring的unit test,找不到配置文件

摘要: 使用spring的unit test,找不到配置文件


java代码:

public class BaseControllerTest extends AbstractModelAndViewTests {
protected XmlWebApplicationContext ctx;

protected MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
protected MockHttpServletResponse response = new MockHttpServletResponse();
protected ModelAndView mv = null;

/**
* Context文件定义函数,可在子类重载
*/
protected String[] getConfigLocations() {
return new String[] {
"/WEB-INF/bookstore-servlet.xml",
"conf/spring/*.xml" };
}

protected final void setUp() {
initWebContext();
onSetUp();
}

/**
* 建立WebApplicationContext
*/
protected void initWebContext() {
ctx = new XmlWebApplicationContext();
ctx.setConfigLocations(getConfigLocations());
ctx.setServletContext(new MockServletContext(""));
ctx.refresh();
}

/**
* 供子类重载的setUp()函数
*/
protected void onSetUp() {
}

}



其中的return new String[] {
"/WEB-INF/bookstore-servlet.xml",
"conf/spring/*.xml" };
这一句,找不到/WEB-INF/bookstore-servlet.xml,怎么弄也找不到。
只有写成 file:///C:/xxx/xxx/bookstore-servlet.xml才能找到。

异常信息如下:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/bookstore-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/bookstore-servlet.xml]

为什么?是哪里的问题?


已经搞定,找人接分


太打击了,,,哪位好心的兄弟姐妹来接分??


满足你的要求


首先,配置文件必须放到classpath下,另外不能用通配符。

接分!!哈!


我晕,没看你的程序。。我们继承的类不一样。
public abstract class MyDependencyInjectionSpringContextTests
extends AbstractTransactionalDataSourceSpringContextTests {
protected ServiceContext context;

/**
* init super class's param requested.
*
*/
public MyDependencyInjectionSpringContextTests() {
}

protected void onSetUpBeforeTransaction() throws Exception {
super.onSetUpBeforeTransaction();
。。。。。
beforeSetUp();
}

protected abstract void beforeSetUp() throws Exception;

protected String[] getConfigLocations() {
String[] config = new String[] {
"osf-applicationContext.xml", "atlas-applicationContext.xml"
};

return config;
}
}



↑返回目录
前一篇: 关于混淆器问题,急!!!!!
后一篇: java调用带参数的exe文件