eclipse中的路径问题

今天重新看了下spring,用eclipse建spring项目测试IOC的时候,发现了一个问题。

这是我的文件结构

测试类位置:
测试类的位置
配置文件位置:
这是配置文件位置
这是测试类代码:

public class TestDi {
	
	@Test
	public void testDiMvc() {
		ApplicationContext ac = new ClassPathXmlApplicationContext("resources/spring-ioc.xml");
		UserInfoController userInfoController = (UserInfoController) ac.getBean("uc");
		userInfoController.show();
	}
	
}

然后问题来了,读不到文件!

接下来就是各种问人百度改路径,发现各种不行,崩溃了快!!!
终于!!改成 “/spring-ioc.xml” 后可以读到了。

public class TestDi {
	
	@Test
	public void testDiMvc() {
		ApplicationContext ac = new ClassPathXmlApplicationContext("/spring-ioc.xml");
		UserInfoController userInfoController = (UserInfoController) ac.getBean("uc");
		userInfoController.show();
	}
	
}

百思不得其解,配置文件明明在src/resources/下,怎么就变成根路径了(黑人问号???)
查了好久,终于在一篇博客找到了答案==》
链接:[https://blog.csdn.net/jbxiaozi/article/details/7367980]。

原因:

在eclipse中,如果把包设置成source folder,编译后目录下的文件就会直接在WEB-INF/classes下即变成了根目录,和src一样source folder是个虚目录,编译后就不存在了,里面的东西是和src放一起的。我屮艸芔茻!!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值