mybatis+spring启动卡死解决方法
来源:互联网 发布:阿根廷经济 知乎 编辑:程序博客网 时间:2024/05/16 14:27
最近在项目中使用mybatis与spring集成,由于项目使用maven分模块打包,经常遇到mybatis mapper少配置子模块或者maven pom中忘记引用子模块导致的mybatis加载不到dao或mapper启动不起来,直接卡死。其实这是mybatis一个bug,在sqlSessionFactory加载的时候没有找到mapper或者dao,mybatis没有把异常抛出。
解决方法就是自己写个sqlSessionFactory抛出异常,替代org.mybatis.spring.SqlSessionFactoryBean。新建一个FixedSqlSessionFactory,集成SqlSessionFactoryBean重写buildSqlSessionFactory(),捕捉异常并且抛出。
需要注意的是,一定要使用
import org.mybatis.spring.SqlSessionFactoryBean;
public class FixedSqlSessionFactory extends SqlSessionFactoryBean{ @Override protected SqlSessionFactory buildSqlSessionFactory() throws IOException { try { return super.buildSqlSessionFactory(); }catch (Exception e){ e.printStackTrace(); }finally { ErrorContext.instance().reset(); } return null; }}
而在spring的sqlSessionFactory配置中,class要写我们的FixedSqlSessionFactory
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configLocation" value="classpath:mybatis-mapper-config.xml"/> </bean>
改写完成后,再重启项目,就可以看到由于没引入mapper产生的异常了,这里抛出的异常可能不只因为mapper没引入,也有其他原因,具体错误具体解决。
1 0
- mybatis+spring启动卡死解决方法
- eclipse启动卡死解决方法
- 阿里云tomcat启动卡死解决方法
- spring 启动卡死的解决
- springMVC项目启动卡死在Initializing Spring root WebApplicationContext
- mybatis 启动死循环 扫包
- Xcode 卡死 解决方法
- Eclipse 启动卡死
- myeclipse启动卡死
- eclipse 启动卡死
- 搜集Eclipse卡死解决方法
- ubuntu 图形界面卡死解决方法
- eclipse上一次没有正确关闭,导致启动的时候卡死错误解决方法
- eclipse上一次没有正确关闭,导致启动的时候卡死错误解决方法
- eclipse上一次没有正确关闭,导致启动的时候卡死错误解决方法
- eclipse上一次没有正确关闭,导致启动的时候卡死错误解决方法
- 启动内核,运行到Freeing init memory: 120K卡死的解决方法
- eclipse上一次没有正确关闭,导致启动的时候卡死错误解决方法
- 社会事件
- Vim新手节省时间的10多个小技巧
- push到github时,每次都要输入用户名和密码的问题
- Spring @Transactional
- SSH BaseDao代码
- mybatis+spring启动卡死解决方法
- git ssh配置 及提交命令
- 获取客户端真实IP
- web项目发布至tomcat的ROOT下方法(开发环境和部署环境)
- 数据结构(六)——二叉树 前序、中序、后序、层次遍历及非递归实现 查找、统计个数、比较、求深度的递归实现
- SimpleDateFormat使用详解
- 针对苹果最新审核要求为应用兼容IPv6
- 字符串算法
- 光衰、功率匹配