1.Spring整合持久化层框架惯例
①引入外部属性文件
②配置数据源
③将数据源装配给SqlSessionFactory
④配置声明式事务
2.Spring整合MyBatis时的特殊设置
①专门jar包
mybatis-spring-1.2.2.jar
http://www.mybatis.org/spring/zh/index.html 插件说明文档
②org.mybatis.spring.SqlSessionFactoryBean
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<property name="typeAliasesPackage" value="com.sirius.mybatis.entity"/>
</bean>
③org.mybatis.spring.mapper.MapperScannerConfigurer
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.sirius.mybatis.mappers"/>
</bean>
3.注意
①事务管理器使用DataSourceTransactionManager
②指定了Mapper扫描器之后,XxxMapper接口的实现类可以直接用于装配,不必设置@Repository
Spring整合MyBatis教程

本文详细介绍Spring框架如何整合MyBatis持久化层框架,包括引入属性文件、配置数据源、装配SqlSessionFactory、声明式事务管理及MyBatis特殊设置等步骤。特别关注了事务管理器、Mapper接口装配及必要的jar包。
2万+

被折叠的 条评论
为什么被折叠?



