首页 > 代码库 > spring配置mybatis3
spring配置mybatis3
mybatis官方网站:http://www.mybatis.org/mybatis-3/zh/configuration.html
<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #757575 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #00b7e0 } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px } p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #00ceb2 } p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #b4eb2a } p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #e0edf9; min-height: 15.0px } span.s1 { color: #e0edf9 } span.s2 { color: #0096ff } span.s3 { color: #000000 } span.s4 { color: #b4eb2a } span.s5 { color: #5fcf13 } span.s6 { color: #00ceb2 } span.s7 { color: #00b7e0 } span.Apple-tab-span { white-space: pre }</style>
<!--第一步:加载配置数据库相关参数-->
<context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
<!--第二步:数据库连接池-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<!--配置连接池属性-->
<property name="driverClassName" value="${jdbc.driverClass}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="1" />
<property name="minIdle" value="1" />
<property name="maxActive" value="20" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
</bean>
<!-- 第三步:sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<property name="mapperLocations" value="classpath*:com/eaglesoul/assistant/dao/mapper/*.mapper"/>
<property name="dataSource" ref="dataSource"/>
</bean>
mybatis-config.xml配置文件:
<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #b4eb2a } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #f4b165 } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #fdd865 } p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #e0edf9; min-height: 15.0px } p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #00b7e0 } p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #00ceb2 } p.p7 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px } span.s1 { color: #00a5ca } span.s2 { color: #00b7e0 } span.s3 { color: #000000 } span.s4 { color: #5fcf13 } span.s5 { color: #00ceb2 } span.s6 { color: #e0edf9 } span.s7 { color: #009193 } span.s8 { color: #d9abef } span.s9 { color: #f4b165 } span.s10 { color: #0096ff } span.s11 { color: #b4eb2a } span.Apple-tab-span { white-space: pre }</style>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>
spring配置mybatis3