spring-mybatis.xml 2.65 KB
<?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:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

    <!-- dataSource -->
    <bean id="cmdbDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="jdbcUrl">
            <value>${local.jdbc.url}</value>
        </property>
        <property name="user">
            <value>${local.jdbc.user}</value>
        </property>
        <property name="password">
            <value>${local.jdbc.password}</value>
        </property>
        <property name="checkoutTimeout" value="3000"/>
        <property name="acquireIncrement" value="2"/>
        <property name="maxPoolSize" value="40"/>
        <property name="minPoolSize" value="5"/>
    </bean>
    <!-- dataSource -->

    <!--mybatis -->
    <bean id="cmdbSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="cmdbDataSource"/>
        <property name="configLocation" value="classpath:META-INF/mybatis/mybatis-config.xml"/>
        <property name="typeAliasesPackage" value="com.model"/>
        <property name="transactionFactory">
            <bean class="org.mybatis.spring.transaction.SpringManagedTransactionFactory"/>
        </property>
    </bean>

    <!--配置Mybatis模版 -->
    <bean id="cmdbSqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="cmdbSqlSessionFactory"/>
    </bean>

    <bean id="cmdbMapperScan" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="cmdbSqlSessionFactory"></property>
        <property name="sqlSessionTemplateBeanName" value="cmdbSqlSessionTemplate"></property>
        <property name="basePackage" value="com.monitor.mysql.mapper"/>
    </bean>

    <bean id="cmdbTxManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="cmdbDataSource"/>
    </bean>

    <bean id="cmdbTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="cmdbDataSource"/>
    </bean>
    <tx:annotation-driven transaction-manager="cmdbTxManager"/>

</beans>