zoukankan      html  css  js  c++  java
  • 可以从Jar外部加载JDBC.properties的Spring-mybatis配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans
            xmlns="http://www.springframework.org/schema/beans"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:tx="http://www.springframework.org/schema/tx"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:aop="http://www.springframework.org/schema/aop"
            xmlns:mvc="http://www.springframework.org/schema/mvc"
            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.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
        <context:annotation-config/>
        <context:component-scan base-package="com.jiuzhou.crawler"/>
    
        <!-- 引入配置文件 -->
        <bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="location" value="file:#{systemProperties['user.dir']}/conf/jdbc.properties"/>
        </bean>
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
              destroy-method="close">
            <property name="driverClassName" value="${jdbc.driver}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
            <!-- 初始化连接大小 -->
            <property name="initialSize" value="${jdbc.initialSize}"></property>
    
            <!-- 连接池最大数量 -->
            <property name="maxActive" value="${jdbc.maxActive}"></property>
    
            <!-- 连接池最大空闲 -->
            <property name="maxIdle" value="${jdbc.maxIdle}"></property>
    
            <!-- 连接池最小空闲-->
            <property name="minIdle" value="${jdbc.minIdle}"></property>
    
            <!-- 获取连接最大等待时间-->
            <property name="maxWait" value="${jdbc.maxWait}"></property>
        </bean>
    
        <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <!-- 自动扫描mapping.xml文件 -->
            <property name="mapperLocations" value="classpath*:com/jiuzhou/crawler/*/sqlxml/*.xml"></property>
        </bean>
    
        <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.jiuzhou.crawler.*.mapper"/>
            <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
        </bean>
    
    
        <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
        <bean id="transactionManager"
              class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"/>
        </bean>
        <tx:annotation-driven transaction-manager="transactionManager"/>
    </beans>
  • 相关阅读:
    php redis操作
    textarea 文本框根据输入内容自适应高度
    ThinkPHP5 微信接口对接公共类
    ThinkPHP5 excel 导入/导出
    NGUI 学习使用
    Unity3d 背景、音效 播放 简单demo
    Unity3D教程:制作与载入AssetBundle
    BuildPipeline.BuildAssetBundle 编译资源包
    C# 如何将对象写入文件
    unity3d IO操作
  • 原文地址:https://www.cnblogs.com/justuntil/p/8042962.html
Copyright © 2011-2022 走看看