单一数据源配置(Spring+Mybatis)

单个数据源的配置流程

 

 

<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource"
        destroy-method="close">
        <property name="driverClass" value="${db.driverClassName}" />
        <property name="jdbcUrl" value="${db.url}" />
        <property name="username" value="${db.user}" />
        <property name="password" value="${db.password}" />
        <property name="idleConnectionTestPeriodInMinutes" value="${bonecp.idleConnectionTestPeriodInMinutes}" />
        <property name="idleMaxAgeInMinutes" value="${bonecp.idleMaxAgeInMinutes}" />
        <property name="minConnectionsPerPartition" value="${bonecp.minConnectionsPerPartition}" />
        <property name="maxConnectionsPerPartition" value="${bonecp.maxConnectionsPerPartition}" />
        <property name="partitionCount" value="${bonecp.partitionCount}" />
        <property name="acquireIncrement" value="${bonecp.acquireIncrement}" />
        <property name="statementsCacheSize" value="${bonecp.statementsCacheSize}" />
        <property name="releaseHelperThreads" value="${bonecp.releaseHelperThreads}" />
    </bean>
<bean id="namedParameterJdbcTemplate"
        class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg ref="dataSource" />
    </bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:mybatis/valla-mybatis-config.xml" /> <property name="dataSource" ref="dataSource" /> <!-- 扫描MyBatis XML映射文件 --> <property name="mapperLocations" value="classpath:mapper/*.xml" /> </bean>

<!-- 扫描所有 Mapper 接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.zmeng.rinascimento.valla.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>

<!-- 配置事务管理 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>


mybatis配置文件

<?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="false" />
        <setting name="lazyLoadingEnabled" value="false" />
        <setting name="aggressiveLazyLoading" value="false" />
    </settings>

    <typeAliases>
        <typeAlias alias="Strategy" type="com.zmeng.rinascimento.rousseau.model.Strategy" />
        <typeAlias alias="StrategyScreen" type="com.zmeng.rinascimento.rousseau.model.StrategyScreen" />
    </typeAliases>

    <mappers>
        <mapper resource="mybatis/strategy-mapper.xml" />
        <mapper resource="mybatis/strategyScreen-mapper.xml" />
    </mappers>

</configuration>

 

posted @ 2019-10-16 17:08  javaeelwh  阅读(321)  评论(0编辑  收藏  举报