首页 > 其他 > 详细

mybatis的配置

时间:2017-01-06 21:42:11      阅读:223      评论:0      收藏:0      [点我收藏+]
技术分享
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">

<!--     <bean id="configer" -->
<!--         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> -->
<!--         <property name="location" value="classpath:application.properties"></property> -->
<!--     </bean> -->
    <context:component-scan base-package="com.service"/>
    <!-- 使用 dbcp2 来管理 数据库连接 -->
    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${driver}"></property>
        <property name="username" value="${username}"></property>
        <property name="password" value="${password}"></property>
        <property name="initialSize" value="${initialSize}"></property>
        <property name="url" value="${url}"></property>
        <property name="maxTotal" value="${maxTotal}"></property>
        <property name="maxIdle" value="${maxIdle}"></property>
        <property name="minIdle" value="${minIdle}"></property>
        <property name="maxWaitMillis" value="${maxWait}"></property>
        <property name="defaultAutoCommit" value="false"></property>
        <!-- 连接空闲后一段时间 被逐出连接池的时间 毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="120000"></property>
    </bean>

    <!-- mybatis 持久化实例 准备 所有的 DAO 对象 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <!-- 读取配置文件 -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
    </bean>

    <!-- 查找 DAO 并将其 放入 spring 容器中便于管理 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.dao"></property>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

    <!-- spring 事务声明 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!-- 事务注解驱动,标注@Transactional的类和方法将具有事务性 -->
    <tx:annotation-driven transaction-manager="transactionManager" />
</beans>
View Code

 

mybatis的配置

原文:http://www.cnblogs.com/javaweb2/p/6257221.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!