spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist

spring 整合Mybatis

运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse

  错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist

  错误原因:找不到我的springmvc.xml,在下面web.xml中是我引用路径,网上找到问题classpath指向路径不是resource路径,所以一直找不到我的xml文件,

  classpath:到你的class路径中查找文件,

  classpath*:不仅包含class的路径,还包括jar文件中(class路径)进行查找

  解决办法:在classpath后面在上“*” 可解决问题,“classpath*:springmvc.xml”

  错误代码:

 1 2017-04-05 08:15:10 [org.springframework.web.servlet.DispatcherServlet]-[INFO] FrameworkServlet ‘springmvc‘: initialization started
 2 2017-04-05 08:15:10 [org.springframework.web.context.support.XmlWebApplicationContext]-[INFO] Refreshing WebApplicationContext for namespace ‘springmvc-servlet‘: startup date [Wed Apr 05 08:15:10 CST 2017]; parent: Root WebApplicationContext
 3 2017-04-05 08:15:10 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [springmvc.xml]
 4 2017-04-05 08:15:10 [org.springframework.web.servlet.DispatcherServlet]-[ERROR] Context initialization failed
 5 org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [springmvc.xml]; nested exception is java.io.FileNotFoundException: class path resource [springmvc.xml] cannot be opened because it does not exist
 6     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
 7     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
 8     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
 9     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
10     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
11     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
12     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
13     at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
14     at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
15     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
16     at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647)
17     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598)
18     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661)
19     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517)
20     at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
21     at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
22     at javax.servlet.GenericServlet.init(GenericServlet.java:160)
23     at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
24     at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
25     at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
26     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
27     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
28     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
29     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
30     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
31     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
32     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
33     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
34     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
35     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
36     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
37     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
38     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
39     at java.lang.Thread.run(Thread.java:722)
40 Caused by: java.io.FileNotFoundException: class path resource [springmvc.xml] cannot be opened because it does not exist
41     at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
42     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
43     ... 33 more

web.xml 配置:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
 3   <display-name>Springmvc_Mybits_store</display-name>
 4   <!-- 加载spring容器 -->
 5       <context-param>
 6           <param-name>contextConfigLocation</param-name>
 7           <param-value>classpath:applicationContext-*.xml</param-value>
 8       </context-param>
 9       <!-- 监听器,扫描通配符 -->
10       <listener>
11           <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
12       </listener>
13   <!-- 前端控制器配置 -->
14     <servlet>
15         <servlet-name>springmvc</servlet-name>
16         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
17         <!--加载springmvc.xml配置-->
18         <init-param>
19             <param-name>contextConfigLocation</param-name>
20             <param-value>classpath:springmvc.xml</param-value>
21         </init-param>
22     </servlet>
23   <!-- servlet映射 -->
24   <servlet-mapping>
25           <servlet-name>springmvc</servlet-name>
26           <url-pattern>*.action</url-pattern>
27   </servlet-mapping>
28   <welcome-file-list>
29     <welcome-file>index.html</welcome-file>
30     <welcome-file>index.htm</welcome-file>
31     <welcome-file>index.jsp</welcome-file>
32     <welcome-file>default.html</welcome-file>
33     <welcome-file>default.htm</welcome-file>
34     <welcome-file>default.jsp</welcome-file>
35   </welcome-file-list>
36 </web-app>
时间: 2024-10-09 23:40:07

spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist的相关文章

解决CXF的java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml] cannot be opened because it does not exist

以下是错误信息 九月 25, 2017 8:22:04 下午 org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh 信息: Refreshing Root WebApplicationContext: startup date [Mon Sep 25 20:22:04 CST 2017]; root of context hierarchy 九月 25, 2017 8:22:04 下午 or

java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist

解决办法: maven创建项目时: META-INF目录下面新建一个xfire文件夹,把services.xml文件放到这个文件夹里,再将整个META-INF拷贝到WEB-INF中 clean一下工程重新加载后启动服务就可以了

Spring整合Mybatis错误解决方案

ERROR:java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransactionFactory.newTransaction() 原因是mybatis-spring整合包是1.0的,换成1.1.1就好了

cxf(3.1.1) 异常Caused by: java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml]

Caused by: java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml] cannot be opened because it does not exist用的最新版本,这个版本中 cxf-extension-soap.xml 不需要了直接在配置文件中删除即可 现在只需要引两个文件 <import resource="classpath:META-INF/cxf/

Spring整合MyBatis(一)MyBatis独立使用

摘要: 本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. MyBatis本是Apache的一个开源项目iBatis,2010年这个项目由Apache Software Foundation迁移到了Google Code,并且改名为MyBatis. MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBatis使用简单的XML或注解用于配

spring 整合Mybatis 《错误集合,总结更新》

错误:nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor  运行环境:jdk1.7.0_17 + tomcat 7 + eclipse spring整合mybatis启动时候出现這个错误: SEVERE: Exception sending context initialized event to listener instance of class org

Spring整合Mybatis的注意事项

初学 Spring 整合 Mybatis,虽然网贴无数,但是每次试行下来,总会发生这样那样的问题.最终经过数天的不断尝试,总算是成功运行了,遇到的多数坑也一一绕过,特此记录已备查: 一.关于依赖包 网上的很多帖子杂七杂八加入了各种依赖包,有时看的人头晕脑胀,经过实测,实际需要的依赖包,只有下面三组: <!-- 1.基础Spring依赖 --> <dependency> <groupId>org.springframework</groupId> <ar

Spring整合MyBatis(三)sqlSessionFactory创建

摘要: 本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. 目录 一.SqlSessionFactoryBean的初始化 二.获取 SqlSessionFactoryBean 实例 通过Spring整合MyBatis的示例,我们感受到了Spring为用户更加快捷地进行开发所做的努力,开发人员的工作效率由此得到了显著的提升.但是,相对于使用来说,我们更想知道其背后所隐藏的秘密,Spring整合MyBatis是如何实现的呢?通过分析整合示例

spring源码剖析(八)spring整合mybatis原理

前言 MyBatis相信很多人都会使用,但是当MyBatis整合到了Spring中,我们发现在Spring中使用更加方便了.例如获取Dao的实例,在Spring的我们只需要使用注入的方式就可以了使用Dao了,完全不需要调用SqlSession的getMapper方法去获取Dao的实例,更不需要我们去管理SqlSessionFactory,也不需要去创建SqlSession之类的了,对于插入操作也不需要我们commit. 既然那么方便,Spring到底为我们做了哪些工作呢,它如何将MyBatis整