idea的spring整合基于xml文件配置的mybatis报Invalid bound statement (not found): com.music.dao.MusicDao.findAll的问题

一、

  题主当时就是自己尝试整合spring和mybatis的时候遇到了这个问题,当时题主只看到了用注解的方式配置的dao层,题主用的是xml文件配置的形式,

  而且坑爹的是题主的两个文件的路径写的也不一致,就导致直接用<property name="basePackage" value="com.music.dao"></property> 导致绑定异常

后来在网上查到了解决的办法 ,就是如果路径一致,(如果一致你也就不会来看到本文了),

两个目录路径不一致的话,就代码??

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--配置扫描器  但是只让他扫描service层和dao层 无需扫描注解-->
    <context:component-scan base-package="com.music">
        <!--exclude不扫描-->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!--整合mybatia和spring-->
    <!--配置连接池-->
    <!--配置数据源 DriverManagerDataSource -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql:///song?serverTimezone=GMT%2B8"></property>
        <property name="username" value="root"></property>
        <property name="password" value="root"></property>
    </bean>
    <!--配置sqlsessionFactory的工厂-->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean" id="factoryBean">
         <property name="dataSource" ref="dataSource"></property>     <!-- ****************目录不一致的情况 要在这里添加这没一条配置******************************************** -->      <!-- *通配符来匹配 **任意文件夹下的 *任意以xml结尾的文件 -->     <property name="mapperLocations" value="classpath:com/music/**/*.xml"></property>     <!-- ************************************************************ -->
</bean> <!--配置dao下的接口 扫描 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" id="MapperScannerConfig"> <property name="basePackage" value="com.music.dao"></property> </bean> </beans>

网上的官方解释文档:http://mybatis.github.io/spring/factorybean.html

原文地址:https://www.cnblogs.com/yifachen/p/12038353.html

时间: 2024-08-13 12:51:34

idea的spring整合基于xml文件配置的mybatis报Invalid bound statement (not found): com.music.dao.MusicDao.findAll的问题的相关文章

spring整合mybatis时候一直报invalid bound statement (not found)

原来是我classpath后少了一个*号导致路径找不到,无法加载Mapper文件 <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSo

Spring的web.xml文件配置

<!-- 1.SpringMVC本身是运行在Spring容器之中,所以需要定义一个Spring容器的基本配置文件路径 --> <context-param> <!-- 配置全局的初始化参数,这个参数依靠ServletContext.getInitParameter()获取 --> <param-name>contextConfigLocation</param-name> <!-- 属性标准名称 --> <!-- 所有的Spri

Mybatis 简单的CRUD 基于XML文件配置

所有的ORM框架学习曲线都是先来一个CRUD爽一爽,下面我们就来CRUD一下,所有的配置都是基于上一篇的配置.废话不多说,直接上代码. <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.d

(spring-第2回)Spring的Schema,基于XML的配置(在IoC容器中装配Bean的前奏片)

要深入了解Spring机制,首先需要知道Spring是怎样在IoC容器中装配Bean的.而了解这一点的前提是,要搞清楚Spring基于Schema的Xml配置方案. 在深入了解之前,必须要先明白几个标签的意思(我会逐步引导读者理解,刚开始的懵懂无所谓,读者自会渐入佳境.初极狭,才通人.复行数十步,豁然开朗.). 什么是XML Schema? 用来描述 XML文档的结构,也被简称为XSD(XML Schema Definition),是一些规则的集合.(方式:通过定义schema文件 如 spri

spring--声明式事务(包含基于注解和基于xml文件的配置方式)

一.基于注解 步骤如下: 引入jar(mysql驱动,c3p0数据源,spring的必要jar) applicationContext.xml的配置 Service和Dao的类上都加上对应的注解使其在ioc容器中,service的方法上面加上注解@Transactional applicationContext.xml的配置: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt

spring,springmvc,mybatis基本整合(一)--xml文件配置方式(2)

spring,springmvc,mybatis基本整合(一)–xml文件配置方式(2)之mapper接口 一,整合结构 二,所需jar包 如上图. 三,整合配置 1,web.xml文件 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://j

Spring 框架的概述以及Spring中基于XML的IOC配置

Spring 框架的概述以及Spring中基于XML的IOC配置 一.简介 Spring的两大核心:IOC(DI)与AOP,IOC是反转控制,DI依赖注入 特点:轻量级.依赖注入.面向切面编程.容器.框架.一站式 优势: 方便解耦:做到编译期不依赖,运行期才依赖 AOP的支持 声明式事务的支持 方便程序的测试 方便整合各种框架 降低JavaEE API的使用难度 Spring源码很厉害 解耦: 耦合包括:类之间的和方法之间的 解决的思路: 在创建对象的时候用反射来创建,而不是new 读取配置文件

Spring AOP--基于XML文件的配置

Spring AOP的配置可以基于注解,也可以基于XML文件.前面几篇都是使用注解的方式.下面介绍下使用XML文件如何配置 使用的测试类和切面类都类似.只需要属于AOP的注解去掉即可.下面是AOP的XML配置: 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:

Spring事务管理--[基于XML的配置]

我觉得自己写的不好,所以先贴一个写的好的帖子 感觉看完不用回来了.... 这是一个大佬写的的博客 : https://www.cnblogs.com/yixianyixian/p/8372832.html 第一:JavaEE 体系进行分层开发,事务处理位于业务层,Spring 提供了分层设计业务层的事务处理解决方 案. 第二:spring 框架为我们提供了一组事务控制的接口.具体在后面的第二小节介绍.这组接口是在 spring-tx-5.0.2.RELEASE.jar 中. 第三:spring