Tomcat配置
Tomcat中植入
Tomcat依赖修改
下载druid的依赖jar,放入到tomcat/lib目录下。
web.xml配置
修改tomcat下的web.xml,里面增加druid配置:增加在web.xml中servlet的default配置后面。
<!-- druid view -->
<servlet>
<servlet-name>DruidStatView</servlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
<init-param>
<!-- 允许清空统计数据 -->
<param-name>resetEnable</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<!-- 用户名 -->
<param-name>loginUsername</param-name>
<param-value>admin</param-value>
</init-param>
<init-param>
<!-- 密码 -->
<param-name>loginPassword</param-name>
<param-value>admin</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DruidStatView</servlet-name>
<url-pattern>/druid/*</url-pattern>
</servlet-mapping>
<!-- druid view -->
context.xml配置
将source中的factory修改为:com.alibaba.druid.pool.DruidDataSourceFactory
<Resource name="prpDataSource"
auth="Container"
type="javax.sql.DataSource"
factory="com.alibaba.druid.pool.DruidDataSourceFactory"
defaultTransactionIsolation="READ_COMMITTED"
username="用户名"
password="密码"
filters="stat,wall"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://127.0.0.1:5432/dbname"
maxActive="96"
minIdle="8"
removeabandoned="true"
removeabandonedtimeout="60"
logabandoned="true">
</Resource>
catalina.properties文件
如果druid没有加载到,再修改catalina.properties文件。
项目中配置
引入pom依赖
<dependency>
<groupId>com.alibaba.druid</groupId>
<artifactId>druid-wrapper</artifactId>
<version>0.2.9</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.9</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.8</version>
</dependency>
context.xml与web.xml配置
参考Tomcat中植入中的相关配置。
filter相关配置
如果项目中有使用Authorization权限拦截的,需要在白名单中配置/druid/路径
<filter>
<filter-name>Authorization</filter-name>
<filter-class>
com.sinosoft.common.AuthorizationFilter
</filter-class>
<init-param>
<param-name>loginPage</param-name>
<param-value>/index.html</param-value>
</init-param>
<init-param>
<param-name>valid</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>
/login.do;
/claim/swfFlowBeforeQuery.do;
/interFaces/;
/prpall/;
/www/;
/druid/;
</param-value>
</init-param>
</filter>