MyBatis问题帮忙看看怎么解决:Could not find result map?

哎码 发布于 2021/10/27 14:02
阅读 102
收藏 0

在一个xml中引入另外一个xml的ResultMap,然后就出问题了:

/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:65177,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -javaagent:/Users/wangbin/Library/Caches/JetBrains/IntelliJIdea2021.2/captureAgent/debugger-agent.jar -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath /Users/wangbin/Downloads/demo-test-mybatis/target/classes:/Users/wangbin/.m2/repository/tk/mybatis/mapper-spring-boot-starter/2.1.5/mapper-spring-boot-starter-2.1.5.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot-starter/2.5.6/spring-boot-starter-2.5.6.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot/2.5.6/spring-boot-2.5.6.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.5.6/spring-boot-autoconfigure-2.5.6.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.5.6/spring-boot-starter-logging-2.5.6.jar:/Users/wangbin/.m2/repository/ch/qos/logback/logback-classic/1.2.6/logback-classic-1.2.6.jar:/Users/wangbin/.m2/repository/ch/qos/logback/logback-core/1.2.6/logback-core-1.2.6.jar:/Users/wangbin/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.14.1/log4j-to-slf4j-2.14.1.jar:/Users/wangbin/.m2/repository/org/apache/logging/log4j/log4j-api/2.14.1/log4j-api-2.14.1.jar:/Users/wangbin/.m2/repository/org/slf4j/jul-to-slf4j/1.7.32/jul-to-slf4j-1.7.32.jar:/Users/wangbin/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/wangbin/.m2/repository/org/yaml/snakeyaml/1.28/snakeyaml-1.28.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/2.5.6/spring-boot-starter-jdbc-2.5.6.jar:/Users/wangbin/.m2/repository/com/zaxxer/HikariCP/4.0.3/HikariCP-4.0.3.jar:/Users/wangbin/.m2/repository/org/springframework/spring-jdbc/5.3.12/spring-jdbc-5.3.12.jar:/Users/wangbin/.m2/repository/org/springframework/spring-tx/5.3.12/spring-tx-5.3.12.jar:/Users/wangbin/.m2/repository/org/mybatis/mybatis/3.4.6/mybatis-3.4.6.jar:/Users/wangbin/.m2/repository/org/mybatis/mybatis-spring/1.3.2/mybatis-spring-1.3.2.jar:/Users/wangbin/.m2/repository/tk/mybatis/mapper-core/1.1.5/mapper-core-1.1.5.jar:/Users/wangbin/.m2/repository/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar:/Users/wangbin/.m2/repository/tk/mybatis/mapper-base/1.1.5/mapper-base-1.1.5.jar:/Users/wangbin/.m2/repository/tk/mybatis/mapper-weekend/1.1.5/mapper-weekend-1.1.5.jar:/Users/wangbin/.m2/repository/tk/mybatis/mapper-spring/1.1.5/mapper-spring-1.1.5.jar:/Users/wangbin/.m2/repository/tk/mybatis/mapper-extra/1.1.5/mapper-extra-1.1.5.jar:/Users/wangbin/.m2/repository/tk/mybatis/mapper-spring-boot-autoconfigure/2.1.5/mapper-spring-boot-autoconfigure-2.1.5.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot-starter-actuator/2.5.6/spring-boot-starter-actuator-2.5.6.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot-actuator-autoconfigure/2.5.6/spring-boot-actuator-autoconfigure-2.5.6.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot-actuator/2.5.6/spring-boot-actuator-2.5.6.jar:/Users/wangbin/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.12.5/jackson-databind-2.12.5.jar:/Users/wangbin/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.12.5/jackson-annotations-2.12.5.jar:/Users/wangbin/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.12.5/jackson-core-2.12.5.jar:/Users/wangbin/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.12.5/jackson-datatype-jsr310-2.12.5.jar:/Users/wangbin/.m2/repository/io/micrometer/micrometer-core/1.7.5/micrometer-core-1.7.5.jar:/Users/wangbin/.m2/repository/org/hdrhistogram/HdrHistogram/2.1.12/HdrHistogram-2.1.12.jar:/Users/wangbin/.m2/repository/org/latencyutils/LatencyUtils/2.0.3/LatencyUtils-2.0.3.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.5.6/spring-boot-starter-web-2.5.6.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot-starter-json/2.5.6/spring-boot-starter-json-2.5.6.jar:/Users/wangbin/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.12.5/jackson-datatype-jdk8-2.12.5.jar:/Users/wangbin/.m2/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.12.5/jackson-module-parameter-names-2.12.5.jar:/Users/wangbin/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/2.5.6/spring-boot-starter-tomcat-2.5.6.jar:/Users/wangbin/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.54/tomcat-embed-core-9.0.54.jar:/Users/wangbin/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/9.0.54/tomcat-embed-el-9.0.54.jar:/Users/wangbin/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.54/tomcat-embed-websocket-9.0.54.jar:/Users/wangbin/.m2/repository/org/springframework/spring-web/5.3.12/spring-web-5.3.12.jar:/Users/wangbin/.m2/repository/org/springframework/spring-beans/5.3.12/spring-beans-5.3.12.jar:/Users/wangbin/.m2/repository/org/springframework/spring-webmvc/5.3.12/spring-webmvc-5.3.12.jar:/Users/wangbin/.m2/repository/org/springframework/spring-aop/5.3.12/spring-aop-5.3.12.jar:/Users/wangbin/.m2/repository/org/springframework/spring-context/5.3.12/spring-context-5.3.12.jar:/Users/wangbin/.m2/repository/org/springframework/spring-expression/5.3.12/spring-expression-5.3.12.jar:/Users/wangbin/.m2/repository/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar:/Users/wangbin/.m2/repository/org/projectlombok/lombok/1.18.22/lombok-1.18.22.jar:/Users/wangbin/.m2/repository/org/slf4j/slf4j-api/1.7.32/slf4j-api-1.7.32.jar:/Users/wangbin/.m2/repository/org/springframework/spring-core/5.3.12/spring-core-5.3.12.jar:/Users/wangbin/.m2/repository/org/springframework/spring-jcl/5.3.12/spring-jcl-5.3.12.jar:/Users/wangbin/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/212.5457.46/IntelliJ IDEA.app/Contents/lib/idea_rt.jar com.example.DemoTestMybatisApplication
Connected to the target VM, address: '127.0.0.1:65177', transport: 'socket'

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.6)

2021-10-27 13:55:00.317  INFO 37876 --- [           main] com.example.DemoTestMybatisApplication   : Starting DemoTestMybatisApplication using Java 11.0.11 on wangbindeMacBook-Pro.local with PID 37876 (/Users/wangbin/Downloads/demo-test-mybatis/target/classes started by wangbin in /Users/wangbin/Downloads/demo-test-mybatis)
2021-10-27 13:55:00.322 DEBUG 37876 --- [           main] com.example.DemoTestMybatisApplication   : Running with Spring Boot v2.5.6, Spring v5.3.12
2021-10-27 13:55:00.322  INFO 37876 --- [           main] com.example.DemoTestMybatisApplication   : No active profile set, falling back to default profiles: default
2021-10-27 13:55:01.714  INFO 37876 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-10-27 13:55:01.726  INFO 37876 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-10-27 13:55:01.727  INFO 37876 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.54]
2021-10-27 13:55:01.798  INFO 37876 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-10-27 13:55:01.798  INFO 37876 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1387 ms
2021-10-27 13:55:02.309  WARN 37876 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderMapper' defined in file [/Users/wangbin/Downloads/demo-test-mybatis/target/classes/com/example/dao/OrderMapper.class]: Invocation of init method failed; nested exception is org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.example.dao.UserMapper.BaseResultMap
2021-10-27 13:55:02.314  INFO 37876 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-10-27 13:55:02.345  INFO 37876 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-10-27 13:55:02.409 ERROR 37876 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderMapper' defined in file [/Users/wangbin/Downloads/demo-test-mybatis/target/classes/com/example/dao/OrderMapper.class]: Invocation of init method failed; nested exception is org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.example.dao.UserMapper.BaseResultMap
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.12.jar:5.3.12]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.12.jar:5.3.12]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.12.jar:5.3.12]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.12.jar:5.3.12]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.12.jar:5.3.12]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.12.jar:5.3.12]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.12.jar:5.3.12]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:925) ~[spring-beans-5.3.12.jar:5.3.12]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.12.jar:5.3.12]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.12.jar:5.3.12]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.6.jar:2.5.6]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.6.jar:2.5.6]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.6.jar:2.5.6]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.6.jar:2.5.6]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.6.jar:2.5.6]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.6.jar:2.5.6]
	at com.example.DemoTestMybatisApplication.main(DemoTestMybatisApplication.java:11) ~[classes/:na]
Caused by: org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.example.dao.UserMapper.BaseResultMap
	at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:346) ~[mybatis-3.4.6.jar:3.4.6]
	at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:290) ~[mybatis-3.4.6.jar:3.4.6]
	at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109) ~[mybatis-3.4.6.jar:3.4.6]
	at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:788) ~[mybatis-3.4.6.jar:3.4.6]
	at org.apache.ibatis.session.Configuration.getMappedStatements(Configuration.java:677) ~[mybatis-3.4.6.jar:3.4.6]
	at tk.mybatis.mapper.mapperhelper.MapperHelper.processConfiguration(MapperHelper.java:279) ~[mapper-core-1.1.5.jar:na]
	at tk.mybatis.spring.mapper.MapperFactoryBean.checkDaoConfig(MapperFactoryBean.java:93) ~[mapper-spring-1.1.5.jar:na]
	at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44) ~[spring-tx-5.3.12.jar:5.3.12]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.12.jar:5.3.12]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.12.jar:5.3.12]
	... 16 common frames omitted
Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.example.dao.UserMapper.BaseResultMap
	at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:888) ~[mybatis-3.4.6.jar:3.4.6]
	at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:640) ~[mybatis-3.4.6.jar:3.4.6]
	at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:344) ~[mybatis-3.4.6.jar:3.4.6]
	... 25 common frames omitted

Disconnected from the target VM, address: '127.0.0.1:65177', transport: 'socket'

Process finished with exit code 1

而同样是一个id的select,引用另外一个XML就可以正常运行,现在就很迷茫,怀疑自己是不是学的时候就理解错了:

    <select id="findUserList" resultMap="com.example.dao.OrderMapper.BaseResultMap">
        select *
        from t_order
    </select>

这是工程整体目录结构:

代码已经上传到gitee了,这个地址:https://gitee.com/consolelog/demo-test-mybatis

其中根目录下的schema.sql是测试用的数据库表结构

 

加载中
0
哎码
哎码

解决了,需要配置mybatis.mapper-locations扫描xml路径,多数据源需要分别配置:https://blog.csdn.net/TreeShu321/article/details/104547973

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部
返回顶部
顶部