eclipse项目报错怎么解决class path resource [beans.xml] cannot be opened because it does not exist

来源:互联网 发布:mac怎么截图怎么保存 编辑:程序博客网 时间:2024/06/04 19:42

eclipse项目报错怎么解决class path resource [beans.xml] cannot be opened because it does not exist 50

Defeatself | 浏览 7866 次
发布于2015-02-03 23:07最佳答案
从错误提示显示资源beans.xml不存在,无法打开。
源目录下beans.xml是不是没有拷贝,一般这种情况是用spring,
如果是的话,你需要用ClassPathXmlApplicationContext类加载你的资源文件,比如:
String[] springConf = {"beans.xml"};
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(springConf);
Main main = ctx.getBean("main", Main.class);
最后的Main是一个类,在spring容器中为bean,获取这个bean的实例。如果不是用spring,请将你的代码贴出来。
追问

beans.xml在src

这是什么错?

0 0
原创粉丝点击