applicationContext.xml文件放置对路径影响:
1
2
3
4
5
|
@Test
public
void
testFindByPage() {
ApplicationContext ctx =
new
<SPAN style=
"COLOR: #ff0000"
>ClassPathXmlApplicationContext</SPAN>(”applicationContext.xml“);
AccountDao dao = ctx.getBean(AccountDao.
class
);
|
但是如果applicationContext.xml文件放置在WEB-INF下面的时候使用jUnit测试的时候编写的路径就要有区别了
如果不这样写,测试的时候就会提示applicationContext.xml文件找不到
1
2
3
4
5
6
7
8
9
10
11
|
private
String conf =
"WebRoot/WEB-INF/applicationContext.xml"
;
@Test
public
void
savetest(){
ApplicationContext ac =
new
<SPAN style=
"COLOR: #ff0000"
>FileSystemXmlApplicationContext</SPAN>(conf);
AllDao ad = ac.getBean(AllDao.
class
);
User u =
new
User();
u.setUsername(
"admin001"
);
u.setPassword(
"123456"
);
ad.register(u);
}
|