java.io.FileNotFoundException: D:\Workspaces\MyEclipse 8.5\spring\applicationContext.xml (系统找不到指定的文

今天 重新写了一个spring项目发现出现这个问题:

 java.io.FileNotFoundException: D:\Workspaces\MyEclipse 8.5\spring\applicationContext.xml (系统找不到指定的文件。)

解决方案:

1

a:
import org.springframework.context.support.FileSystemXmlApplicationContext;
修改为
import org.springframework.context.support.ClassPathXmlApplicationContext;
b:
ApplicationContext context=new FileSystemXmlApplicationContext("applicationContext.xml");
修改为
ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext.xml");

2

spring配置文件放到classpath里,而不是WEB-INF下。

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:/applicationContext.xml");


究其原因:看spring api你会发现FileSystemXmlApplicationContextClassPathXmlApplicationContext,有不同我个人意见这就是导致不同结果的原因:

FileSystemXmlApplicationContext

Standalone XML application context, taking the context definition files from the file system or from URLs, interpreting plain paths as relative file system locations (e.g. "mydir/myfile.txt"). Useful for test harnesses as well as for standalone environments.

NOTE: Plain paths will always be interpreted as relative to the current VM working directory, even if they start with a slash. (This is consistent with the semantics in a Servlet container.) Use an explicit "file:" prefix to enforce an absolute file path.

ClassPathXmlApplicationContext

Standalone XML application context, taking the context definition files from the class path, interpreting plain paths as class path resource names that include the package path (e.g. "mypackage/myresource.txt"). Useful for test harnesses as well as for application contexts embedded within JARs.

希望更明白的人加以指正


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值