druid 参数配置详解
4 不同配置文件
本部分只通过示例的方式展示在不同的环境中进行配置的语法格式,具体要配置哪些参数,请参照 参数配置及说明.
其中 spring boot application.properties 中的配置最为完整,建议参考。
4.1 jdbc中配置连接池
jdbc.properties: jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://172.49.15.55:3306/testdb?useUnicode=true&characterEncoding=utf-8 jdbc.username=test jdbc.password=test jdbc.filters=stat jdbc.maxActive=300 jdbc.initialSize=2 jdbc.maxWait=60000 jdbc.minIdle=1 jdbc.timeBetweenEvictionRunsMillis=60000 jdbc.minEvictableIdleTimeMillis=300000 jdbc.validationQuery=SELECT 'x' jdbc.testWhileIdle=true jdbc.testOnBorrow=false jdbc.testOnReturn=false jdbc.poolPreparedStatements=false jdbc.maxPoolPreparedStatementPerConnectionSize=50
4.2 springs中配置druid
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- ”连接“的基本属性 --> <property name="url" value="jdbc_url" /> <property name="username" value="${jdbc_user}" /> <property name="password" value="${jdbc_password}" /> <!-- 连接池属性 --> <property name="initialSize" value="100" /> <property name="maxActive" value="1000" /> <property name="maxWait" value="60000" /> <property name="minEvictableIdleTimeMillis" value=300000 /> <property name="keepAlive" value=true /> <property name="timeBetweenEvictionRunsMillis" value=-1 /> <property name="minIdle" value="20" /> <property name="removeAbandoned" value="true"/> <property name="removeAbandonedTimeout" value="180"/> <property name="logAbandoned" value="true" /> <property name="testWhileIdle" value="true" /> <property name="validationQuery" value="SELECT 'x'" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <property name="poolPreparedStatements" value="true"/> <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/> <property name="filters" value="stat,wall,slf4j"/> <property name="connectionProperties" value="druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000" /> </bean>
4.3 spring boot application.properties配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource #驱动配置信息 spring.datasource.driver-class-name=com.mysql.jdbc.Driver #基本连接信息 spring.datasource.username = root spring.datasource.password = root spring.datasource.url=jdbc:mysql://192.168.153.23:3306/mytest?useUnicode=true&characterEncoding=utf-8 #连接池属性 spring.datasource.druid.initial-size=15 spring.datasource.druid.max-active=100 spring.datasource.druid.min-idle=15 spring.datasource.druid.max-wait=60000 spring.datasource.druid.time-between-eviction-runs-millis=60000 spring.datasource.druid.min-evictable-idle-time-millis=300000 spring.datasource.druid.test-on-borrow=false spring.datasource.druid.test-on-return=false spring.datasource.druid.test-while-idle=true spring.datasource.druid.validation-query=SELECT 1 spring.datasource.druid.validation-query-timeout=1000 spring.datasource.druid.keep-alive=true spring.datasource.druid.remove-abandoned=true spring.datasource.druid.remove-abandoned-timeout=180 spring.datasource.druid.log-abandoned=true spring.datasource.druid.pool-prepared-statements=true spring.datasource.druid.max-pool-prepared-statement-per-connection-size=20 spring.datasource.druid.filters=stat,wall,slf4j spring.datasource.druid.use-global-data-source-stat=true spring.datasource.druid.preparedStatement=true spring.datasource.druid.maxOpenPreparedStatements=100 spring.datasource.druid.connect-properties.mergeSql=true spring.datasource.druid.connect-properties.slowSqlMillis=5000
赞 (0)