2 3 4 5 6 7 8 9 10 11 12

找不到Spring配置文件路径问题

初学Spring在使用ApplicationContext appCon = new ClassPathXmlApplicationContext("applicationContext.xml");遇到的问题:

许多教程和书上都是说把applicationContext.xmlbeans.xml放到src的目录下即可,但就会出现如上问题。

解决方案

由于ClassPathXmlApplicationContext是在当前路径进行寻找,所以要将applicationContext.xmlbeans.xml放到当前运行文件的同一目录下,就可以解决该问题。

附上Spring的配置文件,方便以后取用

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">
posted @ 2022-11-09 17:11  MrDevil  阅读(323)  评论(0)    收藏  举报