spring 3とproxoolの統合について多くの人が質問しています

2829 ワード

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:
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

スプリング構成

 <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>