1:在WEB-INF目录下建立proxool.xml文件
proxool.xml:
<?xml version="1.0" encoding="UTF-8"?>
<proxool-config>
<proxool>
<alias>db</alias>
<driver-url>jdbc:mysql://localhost:3306/unit?characterEncoding=utf8</driver-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="root" />
<property name="password" value="root" />
</driver-properties>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<maximum-new-connections>20</maximum-new-connections>
<prototype-count>5</prototype-count>
<maximum-connection-count>1000</maximum-connection-count>
<minimum-connection-count>10</minimum-connection-count>
</proxool>
</proxool-config>
2:在web.xml进行配置
<!-- 使用servlet配置 -->
<servlet>
<servlet-name>contextConfigLocation</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- 配置Proxool连接池 -->
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>xmlFile</param-name>
<param-value>WEB-INF/proxool.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 监控Proxool连接池 -->
<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>
这个地方要注意,在加载Spring监听的时候,要把listener形式的用servlet代替。并且加载顺序要在proxool之后。其中,我们还可以配置访问proxool的权限。如下:
<!-- 配置对Proxool的限制访问 -->
<security-constraint>
<web-resource-collection>
<web-resource-name>proxool</web-resource-name>
<url-pattern>/admin</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>manager-gui</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>proxool manager Application</realm-name>
</login-config>
<security-role>
<description>
The role that is required to log in to the Manager Application
</description>
<role-name>manager-gui</role-name>
</security-role>
<error-page>
<error-code>500</error-code>
<location>/error/404.jsp</location>
</error-page>
3:在application.xml中配置数据源
<bean id="MyDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.logicalcobwebs.proxool.ProxoolDriver">
</property>
<property name="url">
<value>proxool.db</value>
</property>
</bean>