maven创建spring项目报错
Exception in thread “main” org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
applicationContext.xml是放在src目录下的,
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); 进行读取
读取不到的原因是根据当前路径进行寻找,File->Project Structure->Modules可以看到Source Folders是不包含src的,所以读取不到。
解决方案:
1、将src添加到Source Folders。
2、利用FileSystemXmlApplicationContext
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
3、再pom.xml中添加
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
这种方法适合各种xml文件找不到