【源码】MyBatis
mybatis-spring
public class SqlSessionFactoryBean implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {
bean初始化
public void afterPropertiesSet() throws Exception { Assert.notNull(this.dataSource, "Property 'dataSource' is required"); Assert.notNull(this.sqlSessionFactoryBuilder, "Property 'sqlSessionFactoryBuilder' is required"); Assert.state(this.configuration == null && this.configLocation == null || this.configuration == null || this.configLocation == null, "Property 'configuration' and 'configLocation' can not specified with together"); this.sqlSessionFactory = this.buildSqlSessionFactory(); }
SqlSessionFactoryBuilder
SqlSessionFactory build(Reader reader)
DefaultSqlSessionFactory
public class DefaultSqlSessionFactory implements SqlSessionFactory {
public SqlSession openSession(boolean autoCommit) { return this.openSessionFromDataSource(this.configuration.getDefaultExecutorType(), (TransactionIsolationLevel)null, autoCommit); }
// ..
}
DefaultSqlSession
public class DefaultSqlSession implements SqlSession { select selectList insert update // ... }
spring事件监听
public void onApplicationEvent(ApplicationEvent event) { if (this.failFast && event instanceof ContextRefreshedEvent) { this.sqlSessionFactory.getConfiguration().getMappedStatementNames(); } }