Mybatis中的错误org.apache.ibatis.exceptions.PersistenceException

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis中的错误org.apache.ibatis.exceptions.PersistenceException相关的知识,希望对你有一定的参考价值。

本人菜鸟刚学用Mybatis写简单的Demo,遇到这个问题很困惑请大神指教
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).log4j:WARN Please initialize the log4j system properly.Exception in thread "main" java.lang.ExceptionInInitializerError at com.main.service.UserService.<clinit>(UserService.java:13) at com.main.service.Test.main(Test.java:9)Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.### The error may exist in SQL Mapper Configuration### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalStateException: Cannot enable lazy loading because CGLIB is not available. Add CGLIB to your classpath. at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:51) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:35) at com.main.service.MybatisUtil.<clinit>(MybatisUtil.java:23) ... 2 moreCaused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalStateException: Cannot enable lazy loading because CGLIB is not available. Add CGLIB to your classpath. at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:105) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:88) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:49) ... 4 moreCaused by: java.lang.IllegalStateException: Cannot enable lazy loading because CGLIB is not available. Add CGLIB to your classpath. at org.apache.ibatis.session.Configuration.setLazyLoadingEnabled(Configuration.java:211) at org.apache.ibatis.builder.xml.XMLConfigBuilder.settingsElement(XMLConfigBuilder.java:197) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:99) ... 6 moreCaused by: java.lang.ClassNotFoundException: Cannot find class: net.sf.cglib.proxy.Enhancer at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:188) at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:87) at org.apache.ibatis.io.Resources.classForName(Resources.java:250) at org.apache.ibatis.session.Configuration.setLazyLoadingEnabled(Configuration.java:209) ... 8 more

在User.xml配置文件中,select属性的resultType——指定输出结果的Java类型(指定单条结果的java类型)的路径出错了。另一个原因在 select后 是resultMap,却写成了resultType。 参考技术A 你的UserMapper是不是定义成类了?应该定义为接口。 参考技术B MyBatisUtil 这个类怎么写的追问

以上是关于Mybatis中的错误org.apache.ibatis.exceptions.PersistenceException的主要内容,如果未能解决你的问题,请参考以下文章

Mybatis中的CDATA标签的用法

MyBatis中的OGNL expression

mybatis绑定错误-- Invalid bound statement (not found)

Mybatis映射文件错误Tomcat无法启动,也不报异常

记录一个mybatis编写xml遇到的错误:java.lang.unsupportedOperationException

Mybatis-select-返回值类型错误理解