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

  • 相关阅读:
    小Z的袜子
    C#操作XML
    C#中接口的实现方法
    C#邮箱批量注册
    C# 委托的使用
    C# socket
    在C#.net中如何操作XML
    C#接口的基础知识
    C#判断网页中是否含有某字符串
    C#多线程处理多个队列的数据
  • 原文地址:https://www.cnblogs.com/WeiHaoLee/p/10823341.html
Copyright © 2011-2022 走看看