标签:defaults 源码分析 images com span etc 创建 factory ssi
1. 首先了解一下mybatis,包含核心jar ,以及spring相关jar.
<!-- Mybatis相关组件 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.3</version> </dependency>
2. 加载mybatis
本文以spring中加载mybatis为参考
<!-- 配置集成Mybatis --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:/config/SQLMapConfig.xml" /> <property name="mapperLocations" value="classpath*:com/chinaap/*/**/infra/mybatis/*Mapper.xml" /> </bean>
接口中有如下方法。
public interface SqlSessionFactory { SqlSession openSession(); SqlSession openSession(boolean autoCommit); SqlSession openSession(Connection connection); SqlSession openSession(TransactionIsolationLevel level); SqlSession openSession(ExecutorType execType); SqlSession openSession(ExecutorType execType, boolean autoCommit); SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level); SqlSession openSession(ExecutorType execType, Connection connection); Configuration getConfiguration(); }
接口的实现类
由sqlSessionFactoryBean产生的是默认的SqlSessionFactory(DefaultSqlSessionFactory)
mybatis源码分析(1)-----sqlSessionFactory创建
标签:defaults 源码分析 images com span etc 创建 factory ssi
原文地址:http://www.cnblogs.com/chihirotan/p/6591425.html