今天刚学习mybatis,遇到了一个错误,纠结了半天的时间,所以将发现的问题和解决得方法写一下。
错误信息如下:
java.lang.ExceptionInInitializerErrorat com.ibatis.po.TestSysArea.testInsert(TestSysArea.java:31)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:585)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)at org.junit.runners.ParentRunner.run(ParentRunner.java:236)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.RuntimeException: Error occurred. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/insert'. Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'AreaCode' in class 'com.ibatis.po.SysArea'at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:89)at com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)at com.ibatis.po.SysAreaDaoImpl.(SysAreaDaoImpl.java:19)... 23 more
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/insert'. Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'AreaCode' in class 'com.ibatis.po.SysArea'at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:86)... 25 more
Caused by: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/insert'. Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'AreaCode' in class 'com.ibatis.po.SysArea'at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:123)at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:84)at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)... 26 more
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/insert'. Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'AreaCode' in class 'com.ibatis.po.SysArea'at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)at com.ibatis.sqlmap.engine.builder.xml.SqlMapParser.parse(SqlMapParser.java:51)at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$11.process(SqlMapConfigParser.java:410)at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)... 30 more
Caused by: java.lang.RuntimeException: Error parsing XPath '/sqlMap/insert'. Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'AreaCode' in class 'com.ibatis.po.SysArea'at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:123)at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:84)at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)... 33 more
Caused by: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'AreaCode' in class 'com.ibatis.po.SysArea'at com.ibatis.common.beans.ClassInfo.getGetterType(ClassInfo.java:287)at com.ibatis.common.beans.GenericProbe.getClassPropertyTypeForGetter(GenericProbe.java:224)at com.ibatis.common.beans.GenericProbe.getPropertyTypeForGetter(GenericProbe.java:153)at com.ibatis.sqlmap.engine.mapping.parameter.InlineParameterMapParser.resolveTypeHandler(InlineParameterMapParser.java:229)at com.ibatis.sqlmap.engine.mapping.parameter.InlineParameterMapParser.newParseMapping(InlineParameterMapParser.java:138)at com.ibatis.sqlmap.engine.mapping.parameter.InlineParameterMapParser.parseInlineParameterMap(InlineParameterMapParser.java:50)at com.ibatis.sqlmap.engine.builder.xml.SqlStatementParser.applyInlineParameterMap(SqlStatementParser.java:427)at com.ibatis.sqlmap.engine.builder.xml.SqlStatementParser.processSqlStatement(SqlStatementParser.java:215)at com.ibatis.sqlmap.engine.builder.xml.SqlStatementParser.parseGeneralStatement(SqlStatementParser.java:120)at com.ibatis.sqlmap.engine.builder.xml.SqlMapParser$19.process(SqlMapParser.java:563)at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)... 37 more
这个问题主要是因为在SysArea 配置文件中,由于SQL语句中赋值语句中变量首字母大写的缘故,所以会报这样的错误,只要我们在写语句时和PO中的属性名一致即可。