本文主要是介绍SSM框架之:Could not resolve bean definition resource pattern[classpath:spring/applicationContext-*.xml],希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
用Maven搭建spring、springmvc、mybatis时运行报错,搞了好久才搞懂:
org.springframework.beans.factory.BeanDefinitionStoreException: Could not resolve bean definition resource pattern
[classpath:spring/applicationContext-*.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/] cannot be resolved to URL because it does not exist
报错的原因分析:
在maven的工程文件src/main/java下的mapper包中有mapper.java和mapper.xml文件,src/main/config目录有spring,mybatis,springmvc的配置文件 。当我们配置如下代码时:
<build> <resources><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resources></build>
maven扫描src/main/java这个文件夹,并且要扫描所有.xml和.properties文件,这样一来可以解决maven扫描mapper.xml缺失的问题,但是由于修改了默认的resource目录,导致src/main/resources的所有文件都不能被扫描,也就出现了applicationContext文件不能被扫描的错误。
解决方法:
如果你的项目是maven项目,你需要在你的pom.xml的<build></build>里面,加这么一段。(由于修改了默认的resource目录,导致src/main/resources的所有文件都不能被扫描,因此还要配多一个):
<resources><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources>
之后运行,完美解决!!!!!
这篇关于SSM框架之:Could not resolve bean definition resource pattern[classpath:spring/applicationContext-*.xml]的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!