您的位置:首页 > 编程语言 > Java开发

spring多数据源的编写

2016-05-16 14:44 441 查看
</pre><pre name="code" class="html">        <bean id="statFilter" class="com.alibaba.druid.filter.stat.StatFilter"
lazy-init="true">
<description>状态过滤器</description>
<property name="logSlowSql" value="true" />
<property name="mergeSql" value="true" />
</bean>
<bean id="readDataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close" lazy-init="true">
<description>只读数据库连接</description>
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url1}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${initialSize}" />
<!-- 连接池最大数量 -->
<property name="maxActive" value="${maxActive}" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${minIdle}" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${maxWait}" />
<!-- -->
<property name="defaultReadOnly" value="true" />
<property name="proxyFilters">
<list>
<ref bean="statFilter" />
</list>
</property>
<property name="filters" value="${druid.filters}" />
<property name="connectionProperties" value="password=${password}" />
<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="${minEvictableIdleTimeMillis}" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${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="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="${initialSize}" />
<property name="maxActive" value="${maxActive}" />
<property name="minIdle" value="${minIdle}" />
<property name="maxWait" value="${maxWait}" />
<property name="proxyFilters">
<list>
<ref bean="statFilter" />
</list>
</property>
<property name="filters" value="${druid.filters}" />
<property name="connectionProperties" value="password=${password}" />
<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="${minEvictableIdleTimeMillis}" />
<property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" />
</bean>
<bean id="dataSource" class="com.paopaozhu.system.core.aspect.ChooseDataSource" lazy-init="true">
<property name="targetDataSources">
<map key-type="java.lang.String" value-type="javax.sql.DataSource">
<entry key="read"  value-ref="readDataSource" />
<entry key="write"  value-ref="writeDataSource" />
</map>
</property>
<property name="defaultTargetDataSource" ref="writeDataSource" />
<property name="methodType">
<map key-type="java.lang.String">
<entry key="read" value=",find,select,count,list,query" />
<entry key="write" value=",add,create,update,delete,remove,"/>
</map>
</property>
</bean>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: