This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-argus-service/src/main/resources/applicationContext-mybatis.xml
RenKaiGe-Office d385e67cd0 1:修改hive使用druid连接池
2:去除某些方法中的警告
2018-08-20 15:20:44 +08:00

179 lines
10 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd"
default-lazy-init="true">
<!-- 引入jdbc.properties,加密密码 ;<context:property-placeholder location="classpath:jdbc.properties"
/> -->
<bean id="propertyConfigurer" class="com.nis.util.PropertyPlaceholderConfigurerCrypt">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
<value>classpath:nis.properties</value>
</list>
</property>
</bean>
<bean id="parentDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"></bean>
<!--数据源定义采用BoneCP连接池 ,业务配置服务数据库 -->
<bean id="ProductDataSource" parent="parentDataSource"
class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.log.driver}"></property>
<property name="jdbcUrl" value="${jdbc.log.url}"></property>
<property name="username" value="${jdbc.log.username}"></property>
<property name="password" value="${jdbc.log.password}"></property>
<!-- 检查数据库连接池中空闲连接的间隔时间单位是分默认值240如果要取消则设置为0 -->
<property name="idleConnectionTestPeriodInMinutes" value="${bonecp.idleConnectionTestPeriodInMinutes}"></property>
<!-- 连接池中未使用的链接最大存活时间单位是分默认值60如果要永远存活设置为0 -->
<property name="idleMaxAgeInMinutes" value="${bonecp.idleMaxAgeInMinutes}" />
<!-- 每个分区最大的连接数 -->
<property name="maxConnectionsPerPartition" value="${bonecp.maxConnectionsPerPartition}" />
<!-- 每个分区最小的连接数 -->
<property name="minConnectionsPerPartition" value="${bonecp.minConnectionsPerPartition}" />
<!-- 分区数 默认值2最小1推荐3-4视应用而定 -->
<property name="partitionCount" value="${bonecp.partitionCount}" />
<!-- 每次去拿数据库连接的时候一次性要拿几个,默认值2 -->
<property name="acquireIncrement" value="${bonecp.acquireIncrement}" />
<!-- 缓存prepared statements的大小默认值0 -->
<property name="statementsCacheSize" value="${bonecp.statementsCacheSize}" />
</bean>
<!--hive数据源定义采用BoneCP连接池 ,业务配置服务数据库 -->
<bean id="HiveDataSource" parent="parentDataSource"
class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.hive.driver}"></property>
<property name="jdbcUrl" value="${jdbc.hive.url}"></property>
<property name="username" value="${jdbc.hive.username}"></property>
<property name="password" value="${jdbc.hive.password}"></property>
<!-- 检查数据库连接池中空闲连接的间隔时间单位是分默认值240如果要取消则设置为0 -->
<property name="idleConnectionTestPeriodInMinutes"
value="${bonecp.hive.idleConnectionTestPeriodInMinutes}"></property>
<!-- 连接池中未使用的链接最大存活时间单位是分默认值60如果要永远存活设置为0 -->
<property name="idleMaxAgeInMinutes" value="${bonecp.hive.idleMaxAgeInMinutes}" />
<!-- 每个分区最大的连接数 -->
<property name="maxConnectionsPerPartition" value="${bonecp.hive.maxConnectionsPerPartition}" />
<!-- 每个分区最小的连接数 -->
<property name="minConnectionsPerPartition" value="${bonecp.hive.minConnectionsPerPartition}" />
<!-- 分区数 默认值2最小1推荐3-4视应用而定 -->
<property name="partitionCount" value="${bonecp.hive.partitionCount}" />
<!-- 每次去拿数据库连接的时候一次性要拿几个,默认值2 -->
<property name="acquireIncrement" value="${bonecp.hive.acquireIncrement}" />
<!-- 缓存prepared statements的大小默认值0 -->
<property name="statementsCacheSize" value="${bonecp.hive.statementsCacheSize}" />
</bean>
<bean id="HiveDataSourceByDruid" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.hive.driver}" />
<property name="url" value="${jdbc.hive.url}" />
<property name="username" value="${jdbc.hive.username}"/>
<property name="password" value="${jdbc.hive.password}"/>
<property name="initialSize" value="${druid.hive.initialSize}" /><!-- 配置初始化连接池数量-->
<property name="minIdle" value="${druid.hive.minIdle}" /><!-- 配置最小连接池数量-->
<property name="maxActive" value="${druid.hive.maxActive}" /><!-- 配置最大连接池数量-->
<property name="maxWait" value="${druid.hive.maxWait}" /><!-- 配置获取连接等待超时的时间 单位毫秒-->
<property name="useUnfairLock" value="${druid.hive.useUnfairLock}"/><!--使用非公平锁-->
<property name="timeBetweenEvictionRunsMillis" value="${druid.hive.timeBetweenEvictionRunsMillis}" /><!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${druid.hive.minEvictableIdleTimeMillis}" /><!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="validationQuery" value="${druid.hive.validationQuery}" /><!--用来检测连接是否有效的sql要求是一个查询语句。 -->
<property name="testWhileIdle" value="${druid.hive.testWhileIdle}" /><!--申请连接的时候检测如果空闲时间大于timeBetweenEvictionRunsMillis执行validationQuery检测连接是否有效。-->
<property name="testOnBorrow" value="${druid.hive.testOnBorrow}" /><!--申请连接时执行validationQuery检测连接是否有效-->
<property name="testOnReturn" value="${druid.hive.testOnReturn}" /><!--归还连接时执行validationQuery检测连接是否有效-->
<property name="poolPreparedStatements" value="${druid.hive.poolPreparedStatements}" /><!-- 打开PSCache并且指定每个连接上PSCache的大小 -->
<property name="maxOpenPreparedStatements" value="${druid.hive.maxOpenPreparedStatements}" /><!--要启用PSCache必须配置大于0当大于0时poolPreparedStatements自动触发修改为true。在Druid中不会存在Oracle下PSCache占用内存过多的问题可以把这个数值配置大一些比如说100 -->
<property name="filters" value="${druid.hive.filters}" /><!-- 配置监控统计拦截的filters去掉后监控界面sql无法统计 -->
</bean>
<bean id="dynamicDataSource" class="com.nis.datasource.DynamicDataSource">
<property name="targetDataSources">
<map key-type="java.lang.String">
<entry value-ref="ProductDataSource" key="dataSourceA"></entry>
</map>
</property>
<property name="defaultTargetDataSource" ref="ProductDataSource"></property>
</bean>
<!-- mybatis 配置扫描相关mapper文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dynamicDataSource"></property>
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- 打印查询语句 -->
<!-- <property name="mapperLocations" value="classpath:com/nis/web/dao/*Dao.xml"></property> -->
</bean>
<!--创建数据映射器,数据映射器必须为接口 -->
<!-- 扫描basePackage下所有以@MyBatisDao注解的接口 -->
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<property name="basePackage" value="com.nis.web.dao" />
<property name="annotationClass" value="com.nis.web.dao.MyBatisDao" />
</bean>
<bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"
lazy-init="true"></bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dynamicDataSource"></property>
</bean>
<!-- 配置事务异常封装 -->
<bean id="persistenceExceptionTranslationPostProcessor"
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"></bean>
<!-- 定义transactionManager作事务管理,get*方法事务为readonly,其它方法按默认设置 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="find*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="query*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="search*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!-- proxy-target-class="true" -->
<aop:config expose-proxy="true">
<aop:pointcut expression="execution(* com.nis.web.service..*Service.*(..))"
id="txPointcut" />
<aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice" />
</aop:config>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dynamicDataSource"></property>
</bean>
</beans>