spring部分:applicationContext.xml文件配置
1.配置数据源 dataSource
<!-- 配置数据源 -->
<bean />
</bean>
2.配置sqlSessionFactory,
2.1 引入dataSource,
2.2 自动扫描mappers.xml文件,
2.3 引入mybatis配置文件
<!-- 配置mybatis的sqlSessionFactory -->
<bean ></property>
</bean>
3.配置dao扫描器,扫描/mappers/*.xml对应的mapper接口类,需要引入sqlSessionFactory
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.java.user.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
4.配置事务
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean />
</bean>
<!-- 配置事务通知属性 -->
<tx:advice />
</tx:attributes>
</tx:advice>
<!-- 配置事务切面 -->
<aop:config>
<aop:pointcut />
</aop:config>