一上午被mybatis的这个问题搞得都没法工作,springboot启动一直报错:
2016-02-19 12:47:45.380 [localhost-startStop-1] WARN o.a.c.loader.WebappClassLoaderBase - The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.lang.Object.wait(Native Method) java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143) com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43) 2016-02-19 12:47:45.398 [main] ERROR o.s.boot.SpringApplication - Application startup failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaCodeRepository': Invocation of init method failed; nested exception is org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.lang.Integer at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) ~[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.0.M5.jar:1.3.0.M5] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:667) [spring-boot-1.3.0.M5.jar:1.3.0.M5] at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:342) [spring-boot-1.3.0.M5.jar:1.3.0.M5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:273) [spring-boot-1.3.0.M5.jar:1.3.0.M5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:980) [spring-boot-1.3.0.M5.jar:1.3.0.M5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:969) [spring-boot-1.3.0.M5.jar:1.3.0.M5] at com.edol.core.Application.main(Application.java:40) [classes/:na] Caused by: org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.lang.Integer at org.apache.ibatis.builder.MapperBuilderAssistant.setStatementResultMap(MapperBuilderAssistant.java:358) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:296) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:718) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:688) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:683) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:183) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:44) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) ~[mybatis-3.3.0-2.jar:3.3.0-2] at com.sun.proxy.$Proxy69.findAll(Unknown Source) ~[na:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_66] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_66] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_66] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_66] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) ~[spring-aop-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201) ~[spring-aop-4.2.1.RELEASE.jar:4.2.1.RELEASE] at com.sun.proxy.$Proxy72.findAll(Unknown Source) ~[na:na] at com.edol.core.dao.area.AreaCodeRepository.init(AreaCodeRepository.java:36) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_66] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_66] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_66] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_66] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:354) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:305) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE] ... 18 common frames omitted Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.Integer at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:818) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:570) ~[mybatis-3.3.0-2.jar:3.3.0-2] at org.apache.ibatis.builder.MapperBuilderAssistant.setStatementResultMap(MapperBuilderAssistant.java:356) ~[mybatis-3.3.0-2.jar:3.3.0-2] ... 43 common frames omitted Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'areaCodeRepository': Invocation of init method failed; nested exception is org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.lang.Integer at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:667) at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:342) at org.springframework.boot.SpringApplication.run(SpringApplication.java:273) at org.springframework.boot.SpringApplication.run(SpringApplication.java:980) at org.springframework.boot.SpringApplication.run(SpringApplication.java:969) at com.edol.core.Application.main(Application.java:40) Caused by: org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.lang.Integer at org.apache.ibatis.builder.MapperBuilderAssistant.setStatementResultMap(MapperBuilderAssistant.java:358) at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:296) at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:109) at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:718) at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:688) at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:683) at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:183) 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.$Proxy69.findAll(Unknown Source) 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:497) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201) at com.sun.proxy.$Proxy72.findAll(Unknown Source) at com.edol.core.dao.area.AreaCodeRepository.init(AreaCodeRepository.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:497) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:354) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:305) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133) ... 18 more Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.Integer at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:818) at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:570) at org.apache.ibatis.builder.MapperBuilderAssistant.setStatementResultMap(MapperBuilderAssistant.java:356) ... 43 more 2016-02-19 12:47:45.408 [DubboShutdownHook] INFO c.a.dubbo.config.AbstractConfig - [DUBBO] Run shutdown hook now., dubbo version: 2.5.3-2, current host: 127.0.0.1 2016-02-19 12:47:45.410 [DubboShutdownHook] INFO c.a.d.r.s.AbstractRegistryFactory - [DUBBO] Close all registries [], dubbo version: 2.5.3-2, current host: 127.0.0.1 Disconnected from the target VM, address: '127.0.0.1:50663', transport: 'socket'
最开始提示说问题很像内存泄漏直接吓着我了,排查了一上午才发现真正问题是这条错误:
Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.Integer at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:818) at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:570) at org.apache.ibatis.builder.MapperBuilderAssistant.setStatementResultMap(MapperBuilderAssistant.java:356) ... 43 more
某人在某个mapper配置文件里把一条查询语句点返回值配错了:
<select id="findMaxTradeIdBySourceAndTradeIdPrefix" resultMap="java.lang.Integer"> SELECT max(out_id) FROM t_account_balance_change_log WHERE source = #{source} AND out_id LIKE concat(#{tradeIdPrefix},"%") </select>
把resultMap改成resultType就好了。
实际上Result Maps collection does not contain value for java.lang.Integer 就是出错的原因,mybatis在错误提示方面做得不好,没有把出错地方的配置文件和配置语句代码行列出来,或者至少把解析哪个类时才出的这种问题提示出来以减少排查范围,当前只能通过提交记录翻改动了哪些配置文件来排查错误。
相关推荐
Caused By: org.apache.ibatis.builder.BuilderException: Could not find SQL statement to include with refid 'SAD02.SAD02_COL' at org.apache.ibatis.builder.xml.XMLStatementBuilder$IncludeNodeHandler....
│ │ │ frame-sourcefiles-org.apache.ibatis.builder.annotation.html │ │ │ frame-sourcefiles-org.apache.ibatis.builder.html │ │ │ frame-sourcefiles-org.apache.ibatis.builder.xml.html │ │ │ ...
- org.apache.ibatis.builder 包:用于构建SqlSessionFactory的类。 - org.apache.ibatis.mapping 包:关于映射器和结果映射的类。 - org.apache.ibatis.type 包:包含各种类型处理器。 - org.apache.ibatis....
3. **org.apache.ibatis.builder**:包含XML和注解解析器,用于构建SQL映射和配置对象。 4. **org.apache.ibatis.mapping**:定义了Mapper接口和ResultMap,用于映射SQL查询结果到Java对象。 5. **org.apache.ibatis...
import org.apache.ibatis.annotations.*; @Mapper public interface UserDao { @Select("SELECT * FROM user") List<User> findAll(); } ``` - **解释**:这里展示了一个简单的 DAO 接口,通过注解的方式定义了...
MyBatis通过`org.apache.ibatis.builder.MapperBuilderAssistant`来处理Mapper接口和XML映射文件的关联。 9. **插件机制**:MyBatis支持自定义插件,可以在Executor、StatementHandler、ParameterHandler和...
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 99; columnNumber: 17; 元素类型为 “configuration” 的内容...
- org.apache.ibatis.builder:包含XML解析和构建SqlSessionFactory的相关类。 - org.apache.ibatis.executor:执行器相关的实现,如SimpleExecutor、ReuseExecutor等。 - org.apache.ibatis.mapping:定义了Mapped ...
另外,确保你的MyBatis-Plus、MyBatis-Spring等相关依赖库的版本兼容,有时版本冲突也可能导致此类问题。 最后,当遇到这种问题时,检查数据库连接、表结构和实体类的字段定义,确保它们之间的一致性。同时,使用...
nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for ...
例如,你可以研究`org.apache.ibatis.builder.xml.XMLConfigBuilder`如何解析配置文件,`org.apache.ibatis.session.SqlSessionFactoryBuilder`如何构建SqlSessionFactory,或者`org.apache.ibatis.executor....
import org.apache.ibatis.session.SqlSessionFactoryBuilder; import com.yihaomen.mybatis.model.User; public class Test { private static SqlSessionFactory sqlSessionFactory; private static Reader ...
nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalStateException: Cannot enable lazy loading because CGLIB is not ...
return builder.build(inputStream); } } ``` 8. **整合Spring** 如果使用Spring框架,可以通过`SqlSessionFactoryBean`在Spring配置文件中配置MyBatis: ```xml <bean id="sqlSessionFactory" class="org...
SqlSessionFactory factory = builder.build(inputStream); try (SqlSession session = factory.openSession()) { UserMapper mapper = session.getMapper(UserMapper.class); User user = mapper.getUser(1); ...
SqlSessionFactory factory = builder.build(inputStream); UserService userService = new UserService(factory); List<User> users = userService.getAllUsers(); for (User user : users) { System.out....
SqlSessionFactory factory = builder.build(inputStream); SqlSession session = factory.openSession(); // 执行 SQL 并获取结果 User user = new User(1, "John Doe"); session.insert("domain.User.insert...
SqlSessionFactory factory = builder.build(reader); SqlSession session = factory.openSession(); List<User> users = session.selectList("com.example.testmybatis.mapper.UserMapper.selectAllUsers"); ...
要实现自定义语言驱动,首先需要创建一个继承自`org.apache.ibatis.builder.BaseBuilder`的类,并重写其中的方法。然后,创建一个实现`org.apache.ibatis.builder.xml.XMLLanguageDriver`接口的类,以定义自定义的...
- `org.apache.ibatis.builder.xml.XMLMapperBuilder`: 这是解析XML映射文件的关键类,其中的`parseNestedResultMap()`方法处理`<resultMap>`标签,包含了多对多映射的解析逻辑。 - `org.apache.ibatis.mapping....