错误描述:
org.springframework.beans.factory.BeanDefinitionStoreException: Could not resolve bean definition resource pattern [classpath:spring/spring-*.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/] cannot be resolved to URL because it does not exist
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:229)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
...
Caused by: java.io.FileNotFoundException: class path resource [spring/] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:463)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:292)
at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1296)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)... 61 more
[WARNING] !RequestLog
错误排查:首先检查xml中对相关配置文件的引入路径是否正确,本项目中有两处:
对比路径,查看项目文件路径,发现文件都是存在的,说明并不是资源文件路径写错.
路径没有错,而且文件也是确实存在的,检查mvn编译后的文件发现资源文件没有被编译,可以尝试重新编译;仍不能解决时,配置pom文件的build > resources标签,配置如下:
<build> <finalName>ssm</finalName> <resources> <resource> <directory>src/main/resources</directory><!-- 资源文件所在文件夹 --> <includes> <include>*.properties</include><!-- 具体路径,按自己的项目配置 --> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> ... </build>
原因是mvn在编译时,会将.properties和.xml文件过滤,不编译这些文件,在最后的war包中自然没有这些文件,引用时也就报错了.