为了账号安全,请及时绑定邮箱和手机立即绑定

请问spring boot 连接池的设置参数?

/ 猿问

请问spring boot 连接池的设置参数?

qq_遁去的一_1 2019-08-20 18:14:28

spring boot 连接池的设置参数


查看完整描述

3 回答

?
潇潇雨雨


a.直接配置2套数据源就像下面最EASY
@Configuration
public class SpringConfig {

@Bean
public DataSource dataSource(){
return new XXDataSource();
}

@Bean
public Counter dataSource2(){
return new XXDataSource();
}
}

b.复合数据源只读分离库实现 complexds
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"
p:initialSize="${druid.initialSize}"
p:minIdle="${druid.minIdle}"
p:maxActive="${druid.maxActive}"
p:maxWait="${druid.maxWait}"
p:timeBetweenEvictionRunsMillis="${druid.timeBetweenEvictionRunsMillis}"
p:minEvictableIdleTimeMillis="${druid.minEvictableIdleTimeMillis}"
p:validationQuery="${druid.validationQuery}"
p:poolPreparedStatements="${druid.poolPreparedStatements}"
p:maxPoolPreparedStatementPerConnectionSize="${druid.maxPoolPreparedStatementPerConnectionSize}"/>

<bean id="slaveDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"
p:url="${slave.jdbc.url}"
p:username="${slave.jdbc.username}"
p:password="${slave.jdbc.password}"
p:initialSize="${slave.druid.initialSize}"
p:minIdle="${slave.druid.minIdle}"
p:maxActive="${slave.druid.maxActive}"
p:maxWait="${slave.druid.maxWait}"
p:timeBetweenEvictionRunsMillis="${slave.druid.timeBetweenEvictionRunsMillis}"
p:minEvictableIdleTimeMillis="${slave.druid.minEvictableIdleTimeMillis}"
p:validationQuery="${slave.druid.validationQuery}"
p:poolPreparedStatements="${slave.druid.poolPreparedStatements}"
p:maxPoolPreparedStatementPerConnectionSize="${slave.druid.maxPoolPreparedStatementPerConnectionSize}"/>

<bean id="complexDataSource" class="com.weghst.pine.complexds.ComplexDataSource">
<constructor-arg index="0" ref="dataSource"/>
<constructor-arg index="1">
<map>
<entry key="#{T(com.weghst.pine.complexds.NamedDS).DEFAULT_SLAVE_NAME}" value-ref="slaveDataSource"/>
</map>
</constructor-arg>
</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="complexDataSource"/>

<tx:annotation-driven transaction-manager="transactionManager"/>

<!--
MyBatis 配置
-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="complexDataSource"/>
<property name="configurationProperties">
<props>
<prop key="defaultScriptingLanguage">org.mybatis.scripting.freemarker.FreeMarkerLanguageDriver</prop>
</props>
</property>
<property name="mapperLocations" value="classpath*:com/weghst/pine/repository/*Mapper.xml"/>
</bean>
<bean id="sqlSessionTemplate" class="com.weghst.pine.util.FastSqlSessionTemplate"
c:sqlSessionFactory-ref="sqlSessionFactory"/>
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.weghst.pine.repository"/>
<property name="annotationClass" value="org.springframework.stereotype.Repository"/>
<property name="sqlSessionTemplateBeanName" value="sqlSessionTemplate"/>
</bean>

<bean id="complexDataSourceInterceptor" class="com.weghst.pine.complexds.ComplexDataSourceInterceptor"/>
<aop:config>
<aop:aspect ref="complexDataSourceInterceptor">
<aop:around method="invoke" pointcut="execution(* com.weghst.pine.repository.*.*(..))"/>
</aop:aspect>
</aop:config>

查看完整回答
反对 2019-08-24
?
隔江千里

创建PageController,编码如下: package org.springboot.sample.controller; import java.util.Date; import java.util.Map; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; ...

查看完整回答
反对 2019-08-24

添加回答

回复

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信