码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-10-16 17:56:28      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:man   box   perl   one   val   pat   pass   ssi   art   

单个数据源的配置流程

技术图片

 

 

<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>

 

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

标签:man   box   perl   one   val   pat   pass   ssi   art   

原文地址:https://www.cnblogs.com/shareTechnologyl/p/11686806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!