spring整合mybatis报错解决之道

lovis lovis     2022-12-21     682

关键词:

报错

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring/springmvc-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/springmvc-context.xml] cannot be opened because it does not exist
Web.xml:

报错原因:

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

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

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

我的web.xml如下

<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.xsd" id="WebApp_ID" version="2.5">
    
    
    <display-name>atcrowdfunding</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:spring/spring-*.xml</param-value>
    </context-param>
    
    <!-- 监听器 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- 字符编码过滤器 -->
    <filter>
        <filter-name>encoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

	    
	<filter>  
	    <filter-name>HiddenHttpMethodFilter</filter-name>  
	    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>  
	</filter>
	<filter-mapping>  
	    <filter-name>HiddenHttpMethodFilter</filter-name>  
	    <servlet-name>springmvc</servlet-name>  
	</filter-mapping> 
    

    
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath*:spring/springmvc-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>*.htm</url-pattern>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    
    <!-- 会话超时时间 -->
    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>
    
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

  标红的那一行缺少一个*

spring+mybatis整合报错

报错信息如下:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sqlSessionFactory'definedinServletContextresource[/WEB-INF/spring/app-config.xml]:Invocationofinitmethodfailed;nestedexceptionisorg.springframework.core.NestedIOException:Failedtoparseconfi... 查看详情

spring整合mybatis框架报错信息(代码片段)

Cause:org.springframework.jdbc.CannotGetJdbcConnectionException:FailedtoobtainJDBCConnection;nestedexceptionisjava.sql.SQLException:Theservertimezonevalue1报错信息Errorqueryingdatabase.Cause:org.springfra 查看详情

spring整合mybatis框架报错信息(代码片段)

Cause:org.springframework.jdbc.CannotGetJdbcConnectionException:FailedtoobtainJDBCConnection;nestedexceptionisjava.sql.SQLException:Theservertimezonevalue1报错信息Errorqueryingdatabase.Cause:org.springframework.jdbc.CannotGetJdbcConnectionException:FailedtoobtainJDBCConnection;nestedexceptionisj... 查看详情

spring,mybatis整合启用tomcat报错

...才能帮你找出错误所在追问web.xml追答你用的spring的注解事务,但看applicationContext.xml中没有明确给出事务管理器的bean,如果没有应该填上啊,不过觉得报错信息似乎不是这个的错,只看出了这么多,再好好研究下吧 ... 查看详情

新手spring整合mybatis报错连接数据库失败

参考技术A问题:运行mybatis-generator是报错:Failedtoexecutegoalorg.mybatis.generator:mybatis-generator-maven-plugin:1.3.5Accessdeniedforuser‘root‘@‘localhost‘(usingpassword:NO)前提是:我在DOS命令下等正常连接mysql,那就排除mysql服务是否启动相关的问题... 查看详情

spring整合mybatis时运行测试代码报错injectionofautowireddependenciesfailed,请各位大神帮忙看看

...一种“半自动化”的ORM实现。 参考技术B没有定义bean,在spring之中 查看详情

解决spring整合mybatis时错误‘org.mybatis.spring.mapper.mapperscannerconfigurer#0‘(代码片段)

警告:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname‘org.mybatis.spring.mapper.MapperScannerConfigurer#0’definedinclasspathresource[spring.xml]:Initializationofbeanfail 查看详情

解决spring整合mybatis时错误‘org.mybatis.spring.mapper.mapperscannerconfigurer#0‘(代码片段)

警告:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname‘org.mybatis.spring.mapper.MapperScannerConfigurer#0’definedinclasspathresource[spring.xml]:Initializationofbeanfail 查看详情

解决spring整合mybatis时错误‘org.mybatis.spring.mapper.mapperscannerconfigurer#0‘(代码片段)

警告:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname‘org.mybatis.spring.mapper.MapperScannerConfigurer#0’definedinclasspathresource[spring.xml]:Initializationofbeanfail 查看详情

springboot+mybatisplus替换mybatis整合报错mappedstatementscollectiondoesnotcontainvalue

mybatisPlus完全兼容mybatis,一般来说直接替换掉就可以了,如果mybatis的数据源不能取消创建的话,就注掉mybatisplus的数据源//@ConfigurationpublicclassDataSourceConfig{//@Bean(name="dataSource2")//@ConfigurationProperties(prefix="spring.datasource 查看详情

解决spring整合mybatis时错误‘org.mybatis.spring.mapper.mapperscannerconfigurer#0‘(代码片段)

警告:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname‘org.mybatis.spring.mapper.MapperScannerConfigurer#0’definedinclasspathresource[spring.xml]:Initializationofbeanfailed;nestedexceptionisjava.lang.NoClassDefFoundError:org/springframework/dao/support/DaoSuppor... 查看详情

今天整合springmvc+mybatis时tomcat启动初始化报错一直解决不了,哪位大哥能帮帮我啊万分感谢

...严重:Exceptionsendingcontextinitializedeventtolistenerinstanceofclassorg.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userService':Injectionofresourcedependenciesfailed;nestedexceptionisorg.springframewor... 查看详情

spring整合mybatis以及配置事务(代码片段)

...  需要做的工作:    1、将mybatis对象的创建交由spring      ①配置第三方带有连接池的数据源      ②spring创建sqlsession对象      ③mybatis通过映射接口创建对象,spring不支持通过接口创建对象,需... 查看详情

springboot3整合mybatis报错:property‘sqlsessionfactory‘or‘sqlsessiontemplate‘arerequired

SpringBoot3整合MyBatis报错:Property‘sqlSessionFactory‘or‘sqlSessionTemplate‘arerequired遇到了一个SpringBoot3整合MyBatis的问题,然后解决了。当然,这其实不是个大问题,只是自己编码时遇到了,然后总结总结分享一下。如果有遇到类似问... 查看详情

spring整合mybatis配置数据源老报错,求大神帮忙看看

...码参考吧<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">    <property name="driverClassName" value="com.mysql.jdbc.Driver" />    <prop... 查看详情

spring与mybatis集成

Spring集成MyBatis​将MyBatis与Spring进行整合,主要解决的问题就是将SqlSessionFactory对象交由Spring来管理。所以,该整合,只需要将SqlSessionFactory的对象生成器SqlSessionFactoryBean注册在Spring容器中,再将其注入给Dao的实现... 查看详情

spring与mybatis集成

Spring集成MyBatis​将MyBatis与Spring进行整合,主要解决的问题就是将SqlSessionFactory对象交由Spring来管理。所以,该整合,只需要将SqlSessionFactory的对象生成器SqlSessionFactoryBean注册在Spring容器中,再将其注入给Dao的实现... 查看详情

spring事务源码分析专题mybatis的使用及跟spring整合原理分析

...如下:本文要解决的是第二点,Mybatis的使用、原理及跟Spring整合原理分析。Mybatis的简单使用搭建项目pom文件添加如下依赖<dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.4.6& 查看详情