1JDBC直连数据配置项
使用cmd进入对应的druid-1.0.4.jar包所在路径;再根据密码执行上述命令后获取密文
java -cp druid-1.0.4.jar com.alibaba.druid.filter.config.ConfigTools PAAAWORD
2修改spring-db.xml的dataSource为Druid配置
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@(description=(address=(host=192.168.1.110)(protocol=tcp)(port=21521))(FAILOVER=on)(LOAD_BALANCE=yes)(connect_data=(SERVER = DEDICATED)(service_name=test)(failover_mode=(type=select)(method=basic)(RETIRES = 20)(DELAY = 15))))" />
<property name="username" value="" />
<property name="password" value="" />
<property name="filters" value="config,stat" />
<property name="connectionProperties" value="config.decrypt=true;druid.stat.slowSqlMillis=3000;druid.stat.logSlowSql=true;druid.stat.mergeSql=true" />
<property name="initialSize" value="20" />
<property name="minIdle" value="20" />
<property name="maxActive" value="50" />
<property name="maxWait" value="60000" />
<property name="timeBetweenEvictionRunsMillis" value="300000" />
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="validationQueryTimeout" value="300000" />
<property name="validationQuery" value="SELECT sysdate from dual" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="50" />
3配置web.xml
<servlet>
<servlet-name>DruidStatViewservlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServletservlet-class>
<init-param>
<param-name>resetEnableparam-name>
<param-value>trueparam-value>
init-param>
servlet>
<servlet-mapping>
<servlet-name>DruidStatViewservlet-name>
<url-pattern>/druid/*url-pattern>
servlet-mapping>
<filter>
<filter-name>DruidWebStatFilterfilter-name>
<filter-class>com.alibaba.druid.support.http.WebStatFilterfilter-class>
<init-param>
<param-name>exclusionsparam-name>
<param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*param-value>
init-param>
filter>
<filter-mapping>
<filter-name>DruidWebStatFilterfilter-name>
<url-pattern>/*url-pattern>
filter-mapping>
Tomcat JNDI数据源配置项
在Tomcat使用JNDI配置DruidDataSource,在/conf/context.xml中,在中加入如下配置:
<Resource name="jdbc/druid-test" factory="com.alibaba.druid.pool.DruidDataSourceFactory"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
url="jdbc:derby:memory:tomcat-jndi;create=true"
filters="stat"
/>
和DBCP几乎一样,迁移十分方便
<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}value>property>
<property name="password" value="${jdbc_password}" />
<property name="filters"><value>statvalue>property>
<property name="maxActive"><value>20value>property>
<property name="initialSize"><value>1value>property>
<property name="maxWait"><value>60000value>property>
<property name="minIdle"><value>1value>property>
<property name="timeBetweenEvictionRunsMillis"><value>60000value>property>
<property name="minEvictableIdleTimeMillis"><value>300000value>property>
<property name="validationQuery"><value>SELECT 'x'value>property>
<property name="testWhileIdle"><value>truevalue>property>
<property name="testOnBorrow"><value>falsevalue>property>
<property name="testOnReturn"><value>falsevalue>property>
<property name="poolPreparedStatements"><value>truevalue>property>
<property name="maxOpenPreparedStatements"><value>20value>property>
bean>
为了避免日志文件多大,
造成问题协查不便以及存储资源浪费,强烈建议把慢SQL监控输出关闭。
druid.stat.logSlowSql=false;
对于配置为true时超出设置阈值的SQL会以ERROR信息显示: