Maven项目启动失败:class path resource [config/spring/] cannot be resolved to URL because it does not exist - Spring Boot-Common On With You - CSDN博客

版权声明:本文为博主原创文章,如果觉得写的不错需要转载,在转载时请注明博文出处! https://blog.csdn.net/Hello_World_QWP/article/details/79398462

基于 Maven + Spring + SpringMVC + Mybatis + MySql + Oracle 的项目基本框架搭建完成后,启动项目时启动失败,主要异常信息:

class path resource [config/spring/] cannot be resolved to URL because it does not exist

局部截图如下:

具体内容一场内容如下:

二月 27, 2018 10:21:30 上午 org.springframework.web.context.ContextLoader initWebApplicationContext严重: Context initialization failedorg.springframework.beans.factory.BeanDefinitionStoreException: Could not resolve bean definition resource pattern [classpath:config/spring/applicationContext-*.xml]; nested exception is java.io.FileNotFoundException: class path resource [config/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)    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:614)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:515)    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5110)    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5633)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1694)    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1684)    at java.util.concurrent.FutureTask.run(Unknown Source)    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)    at java.lang.Thread.run(Unknown Source)Caused by: java.io.FileNotFoundException: class path resource [config/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:492)    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:293)    at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1295)    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)    ... 18 more 二月 27, 2018 10:21:30 上午 org.apache.catalina.core.StandardContext listenerStart严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanDefinitionStoreException: Could not resolve bean definition resource pattern [classpath:config/spring/applicationContext-*.xml]; nested exception is java.io.FileNotFoundException: class path resource [config/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)    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:614)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:515)    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5110)    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5633)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1694)    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1684)    at java.util.concurrent.FutureTask.run(Unknown Source)    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)    at java.lang.Thread.run(Unknown Source)Caused by: java.io.FileNotFoundException: class path resource [config/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:492)    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:293)    at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1295)    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)    ... 18 more 二月 27, 2018 10:21:30 上午 org.apache.catalina.core.StandardContext startInternal严重: One or more listeners failed to start. Full details will be found in the appropriate container log file二月 27, 2018 10:21:30 上午 org.apache.catalina.core.StandardContext startInternal严重: Context [/MsgManagMent] startup failed due to previous errors二月 27, 2018 10:21:30 上午 org.apache.catalina.core.ApplicationContext log信息: Closing Spring root WebApplicationContext二月 27, 2018 10:21:30 上午 org.springframework.web.context.support.XmlWebApplicationContext doClose信息: Closing Root WebApplicationContext: startup date [Tue Feb 27 10:21:30 CST 2018]; root of context hierarchy二月 27, 2018 10:21:30 上午 org.apache.catalina.core.StandardContext listenerStop严重: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListenerjava.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext    at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1032)    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1008)    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:583)    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:116)    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5157)    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5830)    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:221)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:149)    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1694)    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1684)    at java.util.concurrent.FutureTask.run(Unknown Source)    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)    at java.lang.Thread.run(Unknown Source)

解决办法:

无法解析当前 URL,找不到文件!

Web.xml 配置内容如下:

解析当前 Url 需要在 classpath 后加个 “ * ” 即可,如下图:

*注:前题还需要确保配置文件路径、大小写、符号等,错一个都不能找到系统配置文件的。

当然上面个问题解决了,我还遇到其他的问题,一并记录在这儿了,可以参考一下。

在项目的持久层,我使用的是 Mybatis 的 Mapper 将对象映射到数据库,实现数据的持久方案,在运行的时候,出现 “org.apache.ibatis.binding.BindingException ”  的异常,关于这个问题的话,很简单,到项目的 mapper 映射文件夹,可以看到为空,这是由于未加载映射文件导致的,在项目的 pom.xml 配置文件中加入如下图:

为了方便各位的复制我将源码贴一下,在 pom.xml 的末尾加入如下代码片段即可,具体内容如下:

<build>    <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></build>

好了,关于 “ cannot be resolved to URL because it does not exist ” 就解决了,如果还有什么疑问或遇到什么问题,可以给我留言。
歇后语:“共同学习,共同进步”,也希望大家多多关注CSND的IT社区。


Original url: Access
Created at: 2019-04-25 17:49:41
Category: default
Tags: none

请先后发表评论
  • 最新评论
  • 总共0条评论