运行Junit测试类

package cn.bgodata.x.zero.service;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import cn.bgodata.x.zero.core.model.Cube;
import cn.bgodata.x.zero.core.model.Z0Dimension;
import cn.bgodata.x.zero.dao.CubeDAO;
import cn.bgodata.x.zero.dao.DimensionDAO; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring/spring-dao.xml",
"classpath:spring/spring-service.xml"})
public class ServiceTestClass { @Autowired
private DimService dimService; @Autowired
private CubeService cubeService; @Autowired
private CubeDAO cubeDao; @Autowired
private DimensionDAO dimDao; @Test
public void TXtestTX() throws Exception {
Cube c1 = new Cube();
c1.setWormholeId(80001);
c1.setWormholeCode("great cube");
c1.setName("切片与切块Cube"); Z0Dimension dim = new Z0Dimension();
dim.setWormholeId(80999);
dim.setWormholeCode("multi-dimensional domain: 维度");
dim.setName("行政划分");
dim.setCube(c1); dimService.saveDim(dim);
cubeService.saveCube(c1, false);
} }

抛出异常

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.bgodata.x.zero.service.DimService.save
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:196)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:44)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
at com.sun.proxy.$Proxy19.save(Unknown Source)
at cn.bgodata.x.zero.service.ServiceTestClass.TXtestTX(ServiceTestClass.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)

检查service接口及实现、dao接口及实现、dimension-mapper.xml、cube-mapper.xml,以及源码和配置文件路径,皆无误

package cn.bgodata.x.zero.dao;

import cn.bgodata.x.zero.core.model.Cube;

public interface CubeDAO {

    public int save(Cube cube);

}
package cn.bgodata.x.zero.dao;

import java.util.List;

import cn.bgodata.x.zero.core.model.Z0Dimension;

public interface DimensionDAO {

    public List<Z0Dimension> loadAllDimensions();

    public int saveDim(Z0Dimension dim);
}
package cn.bgodata.x.zero.service;

import cn.bgodata.x.zero.core.model.Cube;

public interface CubeService {

    public void saveCube(Cube c, boolean throwExFlag);
}
package cn.bgodata.x.zero.service;

import cn.bgodata.x.zero.core.model.Z0Dimension;
import cn.bgodata.x.zero.dao.DimensionDAO; public interface DimService { public void saveDim(Z0Dimension dimension); public DimensionDAO getDimensionDAO();
}
package cn.bgodata.x.zero.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import cn.bgodata.x.zero.core.model.Cube;
import cn.bgodata.x.zero.dao.CubeDAO;
import cn.bgodata.x.zero.service.CubeService; @Service
public class CubeServiceImpl implements CubeService { @Autowired
private CubeDAO cubeDao; // @Override
public void saveCube(Cube c, boolean throwExFlag) { System.out.println("save cube count is [" + cubeDao.save(c) + "]"); if (throwExFlag) {
throw new RuntimeException("test tx ...");
} } }
package cn.bgodata.x.zero.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import cn.bgodata.x.zero.core.model.Z0Dimension;
import cn.bgodata.x.zero.dao.DimensionDAO;
import cn.bgodata.x.zero.service.DimService; @Service
public class DimServiceImpl implements DimService { @Autowired
private DimensionDAO dimDao; // @Override
public void saveDim(Z0Dimension dimension) {
System.out.println("save dimension count is [" + dimDao.saveDim(dimension) + "]");
} @Override
public DimensionDAO getDimensionDAO() {
// TODO Auto-generated method stub
return dimDao;
} }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.bgodata.x.zero.dao.CubeDAO">
<insert id="save" parameterType="Cube">
insert ignore into WORMHOLE_CUBE (wormhole_id, wormhole_code, name)
values (#{wormholeId}, #{wormholeCode}, #{name})
</insert>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.bgodata.x.zero.dao.DimensionDAO">
<select id="loadAllDimensions" resultType="Z0Dimension">
select
wc.name 'cube.name',
wc.wormhole_code 'cube.wormhole_code',
wc.wormhole_id 'cube.wormhole_id',
wd.name,
wd.wormhole_code,
wd.wormhole_id
from WORMHOLE_CUBE wc inner join WORMHOLE_DIMENSION wd
on wc.wormhole_id = wd.cube_id
</select> <insert id="saveDim" parameterType="Z0Dimension">
insert ignore into WORMHOLE_DIMENSION (wormhole_id, wormhole_code, name, cube_id)
values (#{wormholeId}, #{wormholeCode}, #{name}, #{cube.wormholeId})
</insert>
</mapper>

导致问题的原因在 spring-dao.xml

spring-dao.xml中配置的DAO接口扫描路径不是完全包名(导致异常的原因)

修改 spring-dao.xml

将扫描路径配置为DAO接口所在包的全路径,问题解决。

Spring扫面路径配置不全导致异常 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 的原因的更多相关文章

  1. 异常 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 解决方案

    原来是因为 AssetsMapper.xml 不知道为什么不见了,导致这个异常,在启动项目时的启动任务里调用到了它,然后因为没有这个xml,所以抛出异常 启动信息: C:\extend\Develop ...

  2. 7. mybatis:mapper-locations: 路径放在java路径下报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

    解决方案:在pom.xml文件中的<build>标签内加上以下的<resources>内容即可 <build> <resources> <reso ...

  3. IDEA异常解决: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

    有时候解决问题不仅仅是解决问题.-----jstarseven 最近因为开发需要,需要搭建一个ssm开发框架,采用了开发工具IDEA. 整合完了SSM开发框架之后,发布的时候出现org.apache. ...

  4. spring boot集成mybatis-plus插件进行自定义sql方法开发时报nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    spring boot集成mybatis-plus插件进行自定义sql方法开发时报nested exception is org.apache.ibatis.binding.BindingExcept ...

  5. ssm项目dao层方法异常:org.apache.ibatis.binding.BindingException: Invalid bound statement

    在IntelliJ IDEA中用ssm框架搭建了一个demo项目,在执行到dao层方法时抛出这个异常: org.apache.ibatis.binding.BindingException: Inva ...

  6. mybatis配置时出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

    如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因是Mapper i ...

  7. Spring boot结合mybatis开发的报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

    错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found),经过排查确定是没有找到xml的原因 ...

  8. 【spring boot Mybatis】报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.interview.dao.UserMapper.add

    报错如下: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.i ...

  9. spring boot 集成 mybatis 单元测试Dao层 控制台报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    最近帮同学做毕业程序,采用后端spring boot + mybatis + H2,将框架搭好进行各层的单元测试时,在dao层就出现了错,如图 于是在网上找各种资料,有的说是xml文件和接口没有一一对 ...

随机推荐

  1. 设置Firefox(火狐)浏览器的中文菜单/界面

    步骤一: 设置Firefox浏览器的中文菜单/界面.首先需要查一下正在使用的火狐版本号(小生使用的火狐版本是55.0.3).      步骤二: 下载对应版本的xpi中文插件 其次,访问下面的火狐官方 ...

  2. ES6 系列之私有变量的实现

    前言 在阅读 <ECMAScript 6 入门>的时候,零散的看到有私有变量的实现,所以在此总结一篇. 1. 约定 实现 class Example { constructor() { t ...

  3. 【Go】优雅的读取http请求或响应的数据-续

    原文链接:https://blog.thinkeridea.com/201902/go/you_ya_de_du_qu_http_qing_qiu_huo_xiang_ying_de_shu_ju_2 ...

  4. zepto 事件分析4(事件队列)

    前面分析了zepto的事件绑定,接下来分析事件解绑,先看一下zepto中解绑的off方法: $.fn.off = function(event, selector, callback){ var $t ...

  5. sqlserver 操作数据表语句模板

    从网上搜的,一点一点加吧. -----------设置事务全部回滚----------------- SET XACT_ABORT ON BEGIN BEGIN TRY BEGIN TRANSACTI ...

  6. sql语句求百分比

    此sql语句包括了两个聚合函数做除法求百分比,并保留两位小数,直接输出字符串形式的百分比.以及对case when在聚合函数的应用. SELECT ss.SS_NAME,SS_ID, COUNT(ea ...

  7. C#一个窗体调用另一个窗体的方法

    一个窗体调用另一个窗体的方法:例如:窗体B要调用窗体A中的方法1.首先在窗体A中将窗体A设为静态窗体public static  FormA   m_formA; //设此窗体为静态,其他窗体可调用此 ...

  8. JSJ—案例谈面向对象

    有人告诉我那里遍地都是对象——我们把所有的程序代码放在main()里面,事实上,那根本就不是面向对象的做法,在Java的面向对象中,我们也会看到类和对象的不同,以及对象是如何让你的生活更美好(至少程序 ...

  9. C#设计模式之十外观模式(Facade Pattern)【结构型】

    一.引言 快12点半了,要开始今天的写作了.很快,转眼设计模式已经写了十个了,今天我们要讲[结构型]设计模式的第五个模式,该模式是[外观模式],英文名称是:Facade Pattern.我们先从名字上 ...

  10. 详解Java中对象的软、弱和虚引用的区别

    对于大部分的对象而言,程序里会有一个引用变量来引用该对象,这是最常见的引用方法.除此之外,java.lang.ref包下还提供了3个类:SoftReference.WeakReference和Phan ...