Spring - hibernate配置类方法配置c3p0

来源:互联网 发布:mac brew lnmp 编辑:程序博客网 时间:2024/06/03 17:22


由于hibernate自带的连接池性能较差,而且有8小时断开的缺点,一般使用第三方连接池,如c3p0


1.pom依赖

<dependency>    <groupId>org.hibernate</groupId>    <artifactId>hibernate-c3p0</artifactId>    <version>//hibernate版本一致</version></dependency>



2.配置需要内容

hibernate.connection.provider_class=org.hibernate.c3p0.internal.C3P0ConnectionProviderhibernate.c3p0.min_size=5hibernate.c3p0.max_size=20hibernate.c3p0.timeout=120hibernate.c3p0.idle_test_period=3000


3.


        hibernateProperties.setProperty("hibernate.connection.driver_class", env.getProperty("jdbc.driverClassName"));        hibernateProperties.setProperty("hibernate.connection.url", env.getProperty("jdbc.url"));        hibernateProperties.setProperty("hibernate.connection.username", env.getProperty("jdbc.user"));        hibernateProperties.setProperty("hibernate.connection.password", env.getProperty("jdbc.pass"));        hibernateProperties.setProperty("hibernate.connection.provider_class", env.getProperty("hibernate.connection.provider_class"));        hibernateProperties.setProperty("hibernate.c3p0.min_size", env.getProperty("hibernate.c3p0.min_size"));        hibernateProperties.setProperty("hibernate.c3p0.max_size", env.getProperty("hibernate.c3p0.max_size"));        hibernateProperties.setProperty("hibernate.c3p0.timeout", env.getProperty("hibernate.c3p0.timeout"));        hibernateProperties.setProperty("hibernate.c3p0.idle_test_period", env.getProperty("hibernate.c3p0.idle_test_period"));


0 0
原创粉丝点击