Invalid bound statement (not found): com.lhh.o2o.dao.AreaDao.queryArea
来源:2-7 验证Dao
陌路旅人
2019-04-03
老师,我使用的IDEA,在进行dao测试时,一直报这个异常
四月 03, 2019 1:39:01 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getDefaultTestExecutionListenerClassNames
信息: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
四月 03, 2019 1:39:01 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper instantiateListeners
信息: Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]
四月 03, 2019 1:39:01 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getTestExecutionListeners
信息: Using TestExecutionListeners: [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@45c8e616, org.springframework.test.context.support.DirtiesContextTestExecutionListener@4cdbe50f, org.springframework.test.context.transaction.TransactionalTestExecutionListener@66d33a, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@7cf10a6f]
四月 03, 2019 1:39:01 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring-dao.xml]
四月 03, 2019 1:39:01 下午 org.springframework.context.support.GenericApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.GenericApplicationContext@64616ca2: startup date [Wed Apr 03 13:39:01 CST 2019]; root of context hierarchy
四月 03, 2019 1:39:01 下午 org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
信息: Loaded JDBC driver: com.mysql.jdbc.Driver
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.lhh.o2o.dao.AreaDao.queryArea
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:230)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
at com.sun.proxy.$Proxy13.queryArea(Unknown Source)
at com.lhh.o2o.com.lhh.o2o.dao.AreaDaoTest.testQueryArea(AreaDaoTest.java:20)
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)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
下面是配置文件:
<?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"
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">
<!--配置自动扫描-->
<context:component-scan base-package="com.lhh.o2o.dao"/>
<!-- 1.配置数据库相关参数properties的属性:${url} -->
<context:property-placeholder
location="classpath:jdbc.properties" />
<!-- 数据库连接池 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置sqlSessionFactory对象 -->
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 配置Mybatis全局配置文件:Mybatis-config.xml -->
<!--<property name="configLocation"-->
<!--value="classpath:mybatis-config.xml" />-->
<!-- 给类起别名 -->
<property name="typeAliasesPackage"
value="com.lhh.o2o.entity" />
</bean>
<!-- 配置扫描Dao接口包,动态实现Dao接口,注入到spring容器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName"
value="sqlSessionFactory" />
<!-- 给出需要扫描的Dao接口包 -->
<property name="basePackage" value="com.lhh.o2o.dao" />
</bean>
</beans>
<?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="com.lhh.o2o.dao.AreaDao">
<resultMap id="Area" type="Area">
<id property="areaId" column="area_id" />
<result property="areaName" column="area_name"/>
<result property="priority" column="priority"/>
<result property="createTime" column="create_time"/>
<result property="lastEditTime" column="last_edit_time"/>
</resultMap>
<select id="queryArea" resultMap="Area">
select area_id,area_name,priority,create_time,last_edit_time
from tb_area order by priority DESC
</select>
</mapper>
下面是测试类:
package com.lhh.o2o;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* 配置spring和Junit整合,junit启动时加载springIOC
*
* @author lei_h
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
//告诉junit spring配置文件的位置
@ContextConfiguration({ "classpath:spring-dao.xml" })
public class BaseTest {
}
package com.lhh.o2o.com.lhh.o2o.dao;
import static org.junit.Assert.assertEquals;
import java.util.List;
import com.lhh.o2o.dao.AreaDao;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.lhh.o2o.BaseTest;
import com.lhh.o2o.entity.Area;
public class AreaDaoTest extends BaseTest {
@Autowired
private AreaDao areaDao;
@Test
public void testQueryArea() {
List<Area> arealist = areaDao.queryArea();
assertEquals(2, arealist.size());
}
}
这是结构目录,放的位置应该没错啊
网上百度了很久,依然没解决,麻烦老师帮忙看一下,谢谢老师
1回答
-
翔仔
2019-04-04
同学好,在你没有解决类似问题能力之前,建议你的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="com.lhh.o2o.dao.AreaDao"> <select id="queryArea" resultType="com.lhh.o2o.entity.Area"> SELECT area_id, area_name, priority, create_time, last_edit_time FROM tb_area ORDER BY priority DESC </select> </mapper>
00
相似问题