Spring整合配置Mybatis
来源:互联网 发布:java 线程 sleep 编辑:程序博客网 时间:2024/05/29 03:16
使用Spring 整合 mybatis 的一些全局配置,可以减少开发量,同时约定大于配置也是目前开发的趋势。
mybatis 是一种ORM框架,可以将数据库表与java entity实体类映射起来。
为了减少开发工作量,使用spring-mybatis管理数据库以及mybatis的一些配置属性
一些jdbc基本属性,如jdbc驱动,jdbc登录的用户名,密码等
<property name="jdbcUrl" value="${url}"/>
<property name="user" value="${username}"/>
<property name="password" value="${password}"/>数据库连接池的私有属性,如最大连接池数目,事务自动提交,失败重连重试次数等
<!--c3p0私有属性-->
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<!--关闭连接后不自动commit-->
<property name="autoCommitOnClose"value="false"/>
<!--获取连接超时时间-->
<property name="checkoutTimeout" value="1000"/>
<!--当获取连接失败重试次数-->
<property name="acquireRetryAttempts" value="2"/>配置扫描的对象,如实体类以及mapper对象
``<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据库连接池-->
<property name="dataSource" ref="dataSource"/>
<!--配置mybatis全局配置文件:mybatis-config.xml-->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!--扫描entity包,使用别名,多个用;隔开-->
<property name="typeAliasesPackage" value="com.test.entity"/>
<!--扫描sql配置文件:mapper需要的xml文件-->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>使用Mybatis 一种常用的做法是Dao接口不具体写实现类,而是用mapper和dao接口映射,由spring负责加载dao的实现类,所以要配置具体的dao坐标,以供mybatis扫描。
<!--配置扫描Dao接口包,动态实现DAO接口,注入到spring容器-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--注入SqlSessionFactory-->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!-- 给出需要扫描的Dao接口-->
<property name="basePackage" value="com.test.dao"/>
</bean>
- mybatis整合spring配置
- Spring 整合mybatis配置
- spring整合mybatis配置
- Spring整合配置Mybatis
- spring-mybatis整合配置
- Spring+Mybatis整合配置xml
- mybatis 与spring整合配置
- 二、Mybatis-Spring整合配置
- SpringMVC+Spring+Mybatis整合配置
- Spring整合mybatis简单配置
- spring 整合 mybatis 详细配置
- 【Spring】XML配置整合Mybatis
- Spring+SpringMVC+Mybatis配置整合
- [spring + springmvc + mybatis] 配置整合
- SpringMVC+Spring+Mybatis整合配置
- Spring+SpringMVC+MyBatis整合配置
- Spring整合MyBatis配置方法
- spring-mybatis整合xml配置
- BZOJ 3631 [JLOI2014]松鼠的新家
- 关于个人的公众号方面
- ubuntu16.04下安装php7.0
- 几个jquery插件的例子
- JAVA容器
- Spring整合配置Mybatis
- MySQl的左外连接,右外连接
- JAVA发送接收MQ代码示例
- 182. Duplicate Emails
- C#基本语法
- windows主机与ubuntu虚拟机之间的文件传输
- AC自动机专题——D
- 175. Combine Two Tables
- IP地址,子网掩码,默认网关