spring.dataSource.xml Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wichell-common Show documentation
Show all versions of wichell-common Show documentation
common project com.wichell.wichell jar
The newest version!
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter" lazy-init="true">
<description>状态过滤器</description>
<property name="slowSqlMillis" value="3000" />
<property name="logSlowSql" value="true" />
<property name="mergeSql" value="true" />
</bean>
<bean id="readDataSource" class="com.alibaba.druid.pool.DruidDataSource"
destroy-method="close" init-method="init" lazy-init="true">
<description>只读数据库连接</description>
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${db.reader.url}" />
<property name="username" value="${db.reader.username}" />
<property name="password" value="${db.reader.password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${db.initialSize}" />
<!-- 连接池最大数量 -->
<property name="maxActive" value="${db.maxActive}" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${db.minIdle}" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${db.maxWait}" />
<!-- -->
<property name="defaultReadOnly" value="true" />
<property name="proxyFilters">
<list>
<ref bean="stat-filter" />
</list>
</property>
<property name="filters" value="${druid.filters}" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="timeBetweenLogStatsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${db.minEvictableIdleTimeMillis}" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${db.timeBetweenEvictionRunsMillis}" />
</bean>
<bean id="writeDataSource" class="com.alibaba.druid.pool.DruidDataSource"
destroy-method="close" init-method="init" lazy-init="true">
<description>只写数据库连接</description>
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${db.writer.url}" />
<property name="username" value="${db.writer.username}" />
<property name="password" value="${db.writer.password}" />
<property name="initialSize" value="${db.initialSize}" />
<property name="maxActive" value="${db.maxActive}" />
<property name="minIdle" value="${db.minIdle}" />
<property name="maxWait" value="${db.maxWait}" />
<property name="defaultReadOnly" value="false" />
<property name="proxyFilters">
<list>
<ref bean="stat-filter" />
</list>
</property>
<property name="filters" value="${druid.filters}" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="timeBetweenLogStatsMillis" value="60000" />
<property name="minEvictableIdleTimeMillis" value="${db.minEvictableIdleTimeMillis}" />
<property name="timeBetweenEvictionRunsMillis" value="${db.timeBetweenEvictionRunsMillis}" />
</bean>
<bean id="dataSource" class="com.wichell.core.support.dbcp.ChooseDataSource" lazy-init="true">
<description>数据源</description>
<property name="targetDataSources">
<map key-type="java.lang.String" value-type="javax.sql.DataSource">
<!-- write -->
<entry key="write" value-ref="writeDataSource" />
<!-- read -->
<entry key="read" value-ref="readDataSource" />
</map>
</property>
<property name="defaultTargetDataSource" ref="writeDataSource" />
<property name="methodType">
<map key-type="java.lang.String">
<!-- read -->
<entry key="read" value=",get,select,count,list,query," />
<!-- write -->
<entry key="write" value=",add,insert,create,update,delete,remove," />
</map>
</property>
</bean>
<!-- -->
<bean class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>
</beans> © 2015 - 2025 Weber Informatics LLC | Privacy Policy