Mybatis报错: org.apache.ibatis.exceptions.PersistenceExcept
网络编程 2021-07-05 14:36www.168986.cn编程入门
这篇文章主要介绍了Mybatis报错: .apache.ibatis.exceptions.PersistenceException解决办法的相关资料,需要的朋友可以参考下
Mybatis报错: .apache.ibatis.exceptions.PersistenceException解决办法
一、问题描述
写好配置文件用JUnit进行测试,一运行就报错:
.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: .apache.ibatis.reflection.ReflectionException: Error instantiating class .fendo.entity.Person with invalid types () or values (). Cause: java.lang.NoSuchMethodException: .fendo.entity.Person.<init>() ### The error may exist in /fendo/entity/Person.xml ### The error may involve defaultParameterMap ### The error ourred while setting parameters ### SQL: select from person ### Cause: .apache.ibatis.reflection.ReflectionException: Error instantiating class .fendo.entity.Person with invalid types () or values (). Cause: java.lang.NoSuchMethodException: .fendo.entity.Person.<init>() at .apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23) at .apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107) at .apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98) at .apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:114) at .apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58) at .apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43) at .sun.proxy.$Proxy6.getPersons(Unknown Source) at .fendo.test.TestMybatis.test(TestMybatis.java:40) at sun.reflect.NativeMethodAessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAessorImpl.invoke(NativeMethodAessorImpl.java:62) at sun.reflect.DelegatingMethodAessorImpl.invoke(DelegatingMethodAessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at .junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at .junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at .junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at .junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at .junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at .junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at .junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at .junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at .junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at .junit.runners.ParentRunner$3.run(ParentRunner.java:290) at .junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at .junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at .junit.runners.ParentRunner.aess$000(ParentRunner.java:58) at .junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at .junit.runners.ParentRunner.run(ParentRunner.java:363) at .eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at .eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at .eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at .eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at .eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at .eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: .apache.ibatis.reflection.ReflectionException: Error instantiating class .fendo.entity.Person with invalid types () or values (). Cause: java.lang.NoSuchMethodException: .fendo.entity.Person.<init>() at .apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:83) at .apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:45) at .apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:38) at .apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:535) at .apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:514) at .apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:334) at .apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:294) at .apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:269) at .apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:239) at .apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:153) at .apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:57) at .apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70) at .apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:57) at .apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259) at .apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132) at .apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105) at .apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81) at .apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104) ... 31 more Caused by: java.lang.NoSuchMethodException: .fendo.entity.Person.<init>() at java.lang.Class.getConstructor0(Class.java:3082) at java.lang.Class.getDeclaredConstructor(Class.java:2178) at .apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:57) ... 48 more
二、解决方法
从上面的异常可以看出: Java.lang.NoSuchMethodException: .fendo.entity.Person.<init>()
person这个实体类不能初始化,不能初始化的原因可能是没有构造方法,然后我查看了下类确实没有构造方法,为他添加个构造方法,就可以了。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程