enviroments
transactionManager
There are two TransactionManager types (i.e. type="[JDBC|MANAGED]") that are included with
MyBatis:
• JDBC – This configuration simply makes use of the JDBC commit and rollback facilities
directly. It relies on the connection retrieved from the dataSource to manage the scope of the
transaction.
• MANAGED – This configuration simply does almost nothing. It never commits, or rolls back
a connection. Instead, it lets the container manage the full lifecycle of the transaction (e.g.
a JEE Application Server context). By default it does close the connection. However, some
containers don’t expect this, and thus if you need to stop it from closing the connection, set the
“closeConnection” property to false.
dataSource
The dataSource element configures the source of JDBC Connection objects using the standard JDBC
DataSource interface.
Most MyBatis applications will configure a dataSource as in the example. However, it’s not required.
Realize though, that to facilitate Lazy Loading, this dataSource is required.
There are three built-in dataSource types (i.e. type="[UNPOOLED|POOLED|JNDI]"):
- environments:环境,mybatis可以配置多种环境,default指定使用某种环境。可以达到快速切换环境
- environment:配置一个具体的环境信息,必须有两个标签,id代表当前环境的唯一标识
- transactionManager:事务管理器;JDBC || MANAGED
- 自定义事务管理器:实现TransactionFactory接口,type指定为全类名
- dataSource: 事务管理器的类型;UNPOOLED || POOLED || JNDI
- 自定义数据源:实现DataSourceFactory接口,type是全类名
这些其实都是类的别名!!!