• 【小白日记】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目录下即可
    在这里插入图片描述
    运行程序
    在这里插入图片描述
    解决!

  • 相关阅读:
    长宽广州地区DNS
    修改PHP的memory_limit限制
    适用于Magento的最合适的.htaccess写法
    在magento中如何回复客户的评论
    冲刺!
    冲刺!
    冲刺!
    冲刺!
    冲刺!
    冲刺!
  • 原文地址:https://www.cnblogs.com/WeiHaoLee/p/10823341.html
Copyright © 2020-2023  润新知