首页 > 代码库 > Maven Web项目配置Mybatis出现SqlSessionFactory错误的解决方案
Maven Web项目配置Mybatis出现SqlSessionFactory错误的解决方案
一、错误现象
[html] view plain copy
- 严重: Context initialization failed
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.mybatis.spring.mapper.MapperScannerConfigurer#0‘ defined in URL [file:/F:/Workspaces/.metadata/.me_tcat7/webapps/jade_admin/WEB-INF/classes/config/spring/applicationContext-resources.xml]: Cannot resolve reference to bean ‘SqlSessionFactory‘ while setting bean property ‘sqlSessionFactory‘; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘SqlSessionFactory‘ defined in URL [file:/F:/Workspaces/.metadata/.me_tcat7/webapps/jade_admin/WEB-INF/classes/config/spring/applicationContext-resources.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [config/mybatis/configuration.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating instance. Cause: java.lang.IllegalStateException: Cannot enable lazy loading because CGLIB is not available. Add CGLIB to your classpath.
- at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334)
- at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
二、解决方案
1 在pom.xml中加上reflectasm包,这个包可以提供映射机制。
[html] view plain copy
- <dependency>
- <groupId>com.esotericsoftware.reflectasm</groupId>
- <artifactId>reflectasm</artifactId>
- <version>1.09</version>
- </dependency>
2 在/src/main/webapp/WEB-INF/lib/中添加cglib-3.1.jar
Maven Web项目配置Mybatis出现SqlSessionFactory错误的解决方案
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。