起因
下载阅读mybatis-3.5.7源码,debug时报错如下信息
org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### Cause: java.lang.IllegalStateException: Cannot enable lazy loading because Javassist is not available. Add Javassist to your classpath.
源码位置
JavassistProxyFactory.java
创建 Configuration类,初始化 JavassistProxyFactory时加载JavassistProxyFactory
public JavassistProxyFactory() {
try {
Resources.classForName("javassist.util.proxy.ProxyFactory");
} catch (Throwable e) {
throw new IllegalStateException("Cannot enable lazy loading because Javassist is not available. Add Javassist to your classpath.", e);
}
}
解决办法
注释掉以下内容
<dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>3.2.20</version>
<!-- <scope>compile</scope>-->
<!-- <optional>true</optional>-->
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.27.0-GA</version>
<!-- <scope>compile</scope>-->
<!-- <optional>true</optional>-->
</dependency>