【小白日记】Spring随笔 class path resource [.xml] cannot be opened because it does not exist 原因及解决办法...

编程入门 行业动态 更新时间:2024-10-26 05:23:31

【小白日记】Spring随笔 class path resource [.xml] cannot be opened because it does not exist 原因及<a href=https://www.elefans.com/category/jswz/34/1767401.html style=解决办法..."/>

【小白日记】Spring随笔 class path resource [.xml] cannot be opened because it does not exist 原因及解决办法...

如题,当日在我对照相关教程学习Spring 使用ClassPathXmlApplicationContext时候遇到如下问题

class path resource [.xml] cannot be opened because it does not exist


啥?找不到Xml文件?? 于是我又仔细检查了一下xml文件

对的呀?我这里也的确有xml文件呀?那为什么?

解决办法及原因

后来经过搜索引擎查阅了一些前辈的资料 发现导致出错的原因还是错在xml的位置摆放上面。
再上一篇博客中 当我使用

Resource r = new FileSystemResource("helloMessage.xml");

语法时 把Xml放置到project 根目录 没有任何问题
但是不同于上次的的时这次在我使用

ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");

这中方法调用xml时 放在根目录就行不通了 这时候我们应该把 xml文件放到Src目录下即可

运行程序

解决!

转载于:.html

更多推荐

【小白日记】Spring随笔 class path resource [.xml] cannot be opened because it does not e

本文发布于:2024-02-16 18:57:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1691113.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:解决办法   白日   随笔   原因   class

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!