与Mybatis相关的错误

xiaoxiao2021-02-28  73

testException = org.apache.ibatis.binding.BindingException Invalid bound statement (not found)

项目采用的是maven构建,程序也是参考的网上大牛的开源程序,这里。当我在这个代码的基础上加入一些其他的功能时,程序出现报错:testException = org.apache.ibatis.binding.BindingException Invalid bound statement (not found),该错误说明没有找到mybatis的xml文件中的SQL语句,说明mapper.xml文件没有被扫描到。 我的mapper文件的扫描扫描路径如下,将mapperLocations换成了src/main/resource下的路径

<!-- 配置Mybatis的文件 ,mapperLocations配置**Mapper.xml文件位置,configLocation配置mybatis-config文件位置--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mapperLocations" value="classpath*:mapper/**/*.xml"/> <property name="configLocation" value="classpath:mybatis/mybatis-config.xml" /> <!-- <property name="typeAliasesPackage" value="com.tiantian.ckeditor.model" /> --> </bean>

本来代码之前测试时可以通过的,但是后来不知道为什么,单元测试一直通不过。从底层的SQL语句到高层的Service检查了无数遍,没有用。后来在网上找到方法,将SQL语句的mapper.xml文件放在了src/main/java中扫描不到,将mapper.xml文件放到了src/main/resource文件夹下,单元测试通过,熟悉和绿色又出现了。具体可以看这里: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)新的异常解决方案 解决 IDEA 中src下xml等资源文件无法读取的问题

junit unrooted tests

错误原因:@Test方法中带有参数 单元测试时,偷懒将service层的方法直接复制粘贴到了Test中进行测试,导致有一个测试方法中带有参数,检查了很久才检查出来。出现这种错误,有两个方向去思考:

1. 检查是否在方法前加了@Test 2. 检测测试的方法中,时候有返回类型(不允许),方法是否是void,方法中是否带有参数(不允许带参数)

Open quote is expected for attribute “{1}” associated with an element type “

如果在程序调试过程中,mybatis报这个错误,说明写在xml文件中的sql语句出现了错误,具体错误可能是某个地方忘记加上双引号了。 xml文件中的SQL语句:

<resultMap id="FormulaResultMap" type="com.lin.domain.FormulaInfo" > <result column="NAME" property="name" jdbcType="VARCHAR" /> <result column="CONTENT" property="content" jdbcType="VARCHAR" /> <result column="DES" property="des" jdbcType="VARCHAR" /> </resultMap> <select id="selectFormulaByName" parameterType="java.lang.String" resultMap="FormulaResultMap">//忘记加双引号 select name , content, des from T_CXFX_GSJS_FORMULA WHERE 1 = 1 AND name = #{formulaName,jdbcType=VARCHAR} </select>

我之间在resultMap=”FormulaResultMap”>这里忘记了加双引号,导致调试一直报错。所以告诫看此文章的各位,一定要细心,一个小错误可能一个小时都找不出来,很恼火。

转载请注明原文地址: https://www.6miu.com/read-48745.html

最新回复(0)