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

  • 相关阅读:
    NSArray block用法
    Be JSON (Just Make JSON Easy!) 什么是JSON
    swift循环
    swift学习网站
    利用正则表达式解析URL
    水果瀑布流布局
    iOS文件操作
    PHP HTTP协议:防盗链
    PHP HTTP协议(报头/状态码/缓存)
    PHP 基础知识代码总结
  • 原文地址:https://www.cnblogs.com/WeiHaoLee/p/10823341.html
Copyright © 2011-2022 走看看