zoukankan      html  css  js  c++  java
  • 单一数据源配置(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>
  • 相关阅读:
    Spark Executor内存管理
    Spring中Bean的生命周期及其扩展点
    NIO非阻塞IO
    TCP,UDP和socket,Http之间联系和区别
    md5加密,md5加盐加密和解密
    线程监测方法多久没被调用
    项目部署后,替换.class文件不生效
    mysql存储过程导入表
    java生成二维码
    Map中keySet和entrySet的区别
  • 原文地址:https://www.cnblogs.com/shareTechnologyl/p/11686806.html
Copyright © 2011-2022 走看看