proxool是加载顺序问题,代码如下:
public class ProxoolInitListener implements ServletContextListener { private static final Logger logger = LoggerFactory.getLogger(ProxoolInitListener.class); @Override public void contextDestroyed(ServletContextEvent arg0) { // TODO Auto-generated method stub System.out.println("destroy database pool...."); } @Override public void contextInitialized(ServletContextEvent contextEvent) { String appDir = contextEvent.getServletContext().getRealPath("/"); try { PropertyConfigurator.configure(appDir + "/../conf/" + "proxool.properties"); } catch (ProxoolException e) { logger.error("proxool init error:" + e); //To change body of catch statement use File | Settings | File Templates. return; } } }
proxool.properties(之前采用过xml,但是发现在Linux环境下,配置文件怎么都读取出错,不想浪费时间,改之):
偶放在conf文件夹下:
jdbc-0.proxool.alias=test_pool jdbc-0.proxool.driver-url=jdbc:mysql://127.0.0.1:3306/mytest?useUnicode=true&characterEncoding=gbk jdbc-0.proxool.driver-class=com.mysql.jdbc.Driver jdbc-0.user=root jdbc-0.password=123 jdbc-0.proxool.house-keeping-sleep-time=40000 jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE jdbc-0.proxool.maximum-connection-count=10 jdbc-0.proxool.minimum-connection-count=5 jdbc-0.proxool.maximum-connection-lifetime=18000000 jdbc-0.proxool.simultaneous-build-throttle=5 jdbc-0.proxool.recently-started-threshold=40000 jdbc-0.proxool.overload-without-refusal-lifetime=50000 jdbc-0.proxool.maximum-active-time=60000 jdbc-0.proxool.verbose=true jdbc-0.proxool.trace=true jdbc-0.proxool.fatal-sql-exception=Fatal error jdbc-0.proxool.prototype-count=2
spring 配置
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>org.logicalcobwebs.proxool.ProxoolDriver</value> </property> <property name="url"> <value>proxool.test_pool</value> </property> </bean>
web.xml配置(放在最前面吧)
<!-- Proxool连接池 --> <listener> <listener-class> com.test.db.ProxoolInitListener </listener-class> </listener>