问答详情
源自:4-7 mybatis整合Spring编码

spring和mybatis配置问题

INFO: Closing org.springframework.context.support.GenericApplicationContext@675d3402: startup date [Tue Oct 11 23:44:05 CST 2016]; root of context hierarchy

org.apache.ibatis.builder.IncompleteElementException: Could not find result map org.seckill.dao.SeckillDao.Seckill

    at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:346)
    at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:278)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109)
    at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:760)
    at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:730)
    at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:725)
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:210)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
    at com.sun.proxy.$Proxy17.queryById(Unknown Source)
    at org.seckill.dao.SeckillDaoTest.reduceNumber(SeckillDaoTest.java:33)
    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:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
    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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for org.seckill.dao.SeckillDao.Seckill
    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:860)
    at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:612)
    at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:344)
    ... 44 more



<?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">
   <!-- 配置整合MyBatis过程 -->
   <!-- 1:配置数据库相关参数的工作 -->
   <context:property-placeholder location="classpath:jdbc.properties"/>
   <!-- 2:数据库连接池 -->
   <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
       <!-- 配置连接池属性 -->
       <property name="driverClass" value="${driver}"/>
       <property name="jdbcUrl" value="${url}"/>
       <property name="user" value="${username}"/>
       <property name="password" value="${password}"/>

       <!-- c3p0连接池私有属性 -->
       <property name="maxPoolSize" value="30"/>
       <property name="minPoolSize" value="10"/>
       <!-- 关闭连接后不自动commit -->
       <property name="autoCommitOnClose" value="false"/>
       <!-- 获取连接超时时间 -->
       <property name="checkoutTimeout" value="1000"/>
       <!-- 当获取连接失败,重试的次数 -->
       <property name="acquireRetryAttempts" value="2"/>
   </bean>

   <!-- 3:配置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"/>
       <!-- 扫描entity包,使用别名 org.seckill.entity.Seckill-->
       <property name="typeAliasesPackage" value="org.seckill.entity"/>
       <!-- 扫描sql配置文件:mapper需要的xml文件 -->
       <property name="mapperLocations" value="classpath:mapper/*.xml"/>
   </bean>

   <!-- 4:配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
   <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
       <!-- 注入sqlSessionFactory -->
       <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
       <!-- 给出扫描Dao接口的包 -->
       <property name="basePackage" value="org.seckill.dao"/>
   </bean>

</beans>


提问者:l_rambo 2016-10-11 23:50

个回答

  • 总在盼望总在失望
    2016-10-13 16:32:48
    已采纳

    Result Maps collection does not contain value for org.seckill.dao.SeckillDao.Seckill的意思是结果集不包含值org.seckill.dao.seckilldao,仔细查看你配置路径有没有错误

  • shine_由衷AZ
    2018-04-11 22:20:17

    Invalid bound statement (not found): com.mmall.dao.UserMapper.checkUsername

    我这种又怎么解决诶