Idea中Spring项目xml配置的有关classPath问题

最近刚学Spring,开发工具IDEA用的也不是很熟,最近写了一个Spring的简单Demo,Bean的装配用的是基于XMl的配置,但是用

ClassPathXmlApplicationContext("sound.xml");获取配置文件时经常报错,找不到资源文件,如示:

IOException parsing XML document from class path resource [src/soundsystem/sound.xml]; nested exception is java.io.FileNotFoundException: class path resource [src/soundsystem/sound.xml] cannot be opened because it does not exist

碰到这个问题,可能是路径问题,或者是你的资源文件xml没有添加src目录下

 但是最终的访问路径应该是要和项目的output path目录下的路径一致,关于output path的配置在File 里的Project Structure设置

 项目启动后,在目录下会生成一个out目录,里面可以看到你添加在src目录下的xml文件,当然这个时候你可以复制其他配置文件进去,只要路劲正确就可以访问

   

     对应的目录结构就是前面在Project Structure里设置的,默认为out/production/项目名/包结构

猜你喜欢

转载自blog.csdn.net/weixin_40672761/article/details/83784871
今日推荐