Mybatis报错: org.apache.ibatis.exceptions.PersistenceException解决办法
程序员文章站
2023-12-16 12:45:52
mybatis报错: org.apache.ibatis.exceptions.persistenceexception解决办法
一、问题描述
写好配置文件用junit...
mybatis报错: org.apache.ibatis.exceptions.persistenceexception解决办法
一、问题描述
写好配置文件用junit进行测试,一运行就报错:
org.apache.ibatis.exceptions.persistenceexception: ### error querying database. cause: org.apache.ibatis.reflection.reflectionexception: error instantiating class com.fendo.entity.person with invalid types () or values (). cause: java.lang.nosuchmethodexception: com.fendo.entity.person.<init>() ### the error may exist in com/fendo/entity/person.xml ### the error may involve defaultparametermap ### the error occurred while setting parameters ### sql: select * from person ### cause: org.apache.ibatis.reflection.reflectionexception: error instantiating class com.fendo.entity.person with invalid types () or values (). cause: java.lang.nosuchmethodexception: com.fendo.entity.person.<init>() at org.apache.ibatis.exceptions.exceptionfactory.wrapexception(exceptionfactory.java:23) at org.apache.ibatis.session.defaults.defaultsqlsession.selectlist(defaultsqlsession.java:107) at org.apache.ibatis.session.defaults.defaultsqlsession.selectlist(defaultsqlsession.java:98) at org.apache.ibatis.binding.mappermethod.executeformany(mappermethod.java:114) at org.apache.ibatis.binding.mappermethod.execute(mappermethod.java:58) at org.apache.ibatis.binding.mapperproxy.invoke(mapperproxy.java:43) at com.sun.proxy.$proxy6.getpersons(unknown source) at com.fendo.test.testmybatis.test(testmybatis.java:40) 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.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:26) at org.junit.internal.runners.statements.runafters.evaluate(runafters.java:27) at org.junit.runners.parentrunner.runleaf(parentrunner.java:325) at org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:78) at org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:57) 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.junit.runners.parentrunner.run(parentrunner.java:363) at org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:86) at org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) at org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:459) at org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:675) at org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:382) at org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:192) caused by: org.apache.ibatis.reflection.reflectionexception: error instantiating class com.fendo.entity.person with invalid types () or values (). cause: java.lang.nosuchmethodexception: com.fendo.entity.person.<init>() at org.apache.ibatis.reflection.factory.defaultobjectfactory.instantiateclass(defaultobjectfactory.java:83) at org.apache.ibatis.reflection.factory.defaultobjectfactory.create(defaultobjectfactory.java:45) at org.apache.ibatis.reflection.factory.defaultobjectfactory.create(defaultobjectfactory.java:38) at org.apache.ibatis.executor.resultset.defaultresultsethandler.createresultobject(defaultresultsethandler.java:535) at org.apache.ibatis.executor.resultset.defaultresultsethandler.createresultobject(defaultresultsethandler.java:514) at org.apache.ibatis.executor.resultset.defaultresultsethandler.getrowvalue(defaultresultsethandler.java:334) at org.apache.ibatis.executor.resultset.defaultresultsethandler.handlerowvaluesforsimpleresultmap(defaultresultsethandler.java:294) at org.apache.ibatis.executor.resultset.defaultresultsethandler.handlerowvalues(defaultresultsethandler.java:269) at org.apache.ibatis.executor.resultset.defaultresultsethandler.handleresultset(defaultresultsethandler.java:239) at org.apache.ibatis.executor.resultset.defaultresultsethandler.handleresultsets(defaultresultsethandler.java:153) at org.apache.ibatis.executor.statement.preparedstatementhandler.query(preparedstatementhandler.java:57) at org.apache.ibatis.executor.statement.routingstatementhandler.query(routingstatementhandler.java:70) at org.apache.ibatis.executor.simpleexecutor.doquery(simpleexecutor.java:57) at org.apache.ibatis.executor.baseexecutor.queryfromdatabase(baseexecutor.java:259) at org.apache.ibatis.executor.baseexecutor.query(baseexecutor.java:132) at org.apache.ibatis.executor.cachingexecutor.query(cachingexecutor.java:105) at org.apache.ibatis.executor.cachingexecutor.query(cachingexecutor.java:81) at org.apache.ibatis.session.defaults.defaultsqlsession.selectlist(defaultsqlsession.java:104) ... 31 more caused by: java.lang.nosuchmethodexception: com.fendo.entity.person.<init>() at java.lang.class.getconstructor0(class.java:3082) at java.lang.class.getdeclaredconstructor(class.java:2178) at org.apache.ibatis.reflection.factory.defaultobjectfactory.instantiateclass(defaultobjectfactory.java:57) ... 48 more
二、解决方法
从上面的异常可以看出: java.lang.nosuchmethodexception: com.fendo.entity.person.<init>()
person这个实体类不能初始化,不能初始化的原因可能是没有构造方法,然后我查看了下类确实没有构造方法,为他添加个构造方法,就可以了。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
推荐阅读
-
Mybatis报错: org.apache.ibatis.exceptions.PersistenceException解决办法
-
MySQL5.7 group by新特性报错1055的解决办法
-
MSSQL2005数据附加失败报错3456解决办法
-
怎么解决ie停止工作?IE已停止工作报错的详细解决办法
-
Android扫描二维码时出现用户禁止权限报错问题解决办法
-
Mybatis报错: org.apache.ibatis.exceptions.PersistenceException解决办法
-
Navicat Premium 10.0.5中文版 oracle连接字符集报错解决办法
-
QQ音乐打不开一运行就报错的解决办法
-
MySQL5.7 group by新特性报错1055的解决办法
-
IE浏览器报错出现“网页上有错误”提示的解决办法