码迷,mamicode.com
首页 > Web开发 > 详细

Unable to resolve name [org.hibernate.connection.ProxoolConnectionProvider] as strategy ...

时间:2015-11-13 19:09:13      阅读:1321      评论:0      收藏:0      [点我收藏+]

标签:hibernate

一 出现问题:


在Hibernate里配置proxool数据库连接池时出现了标题中的报错信息


Initial SessionFactory creation failed.org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]

...

Stacktrace:] with root cause

org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.connection.ProxoolConnectionProvider] as strategy [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]

at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:113)

at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:191)

at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:111)

at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:41)

at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)

at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)

at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)

at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)

at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)

...


出现该报错后,百度之后未能解决问题,因此记录下自己的解决方案


二 问题分析:


根据出错信息提示,主要是找不到“org.hibernate.connection.ProxoolConnectionProvider”这个Class文件,而这个类是在hibernate.cfg.xml中使用到的

技术分享


于是,我就在Hibernate的依赖包里仔细看了下,确实没有这个类

技术分享

到这里,原因已经很明显了,那就是:

    在最新版的Hibernate(hibernate-release-5.0.2.Final)里,lib/required里已经没有集成第三方的数据库连接池了,因此会出现类找到不到的情况。


三 解决方案:


方案1: 

将hibernate-core-5.0.2.Final.jar删掉,并且添加:hibernate3.jar,commons-collections-   3.1.jar,slf4j-api-1.7.12.jar,slf4j-log4j12-1.7.12.jar这几个jar包就可以正常运行了


当然,删掉新的jar包去用旧的jar包这种方式我个人认为是不太恰当的,因此有了方案2

方案2:

原来的jar包不变

(1)添加:hibernate-proxool-5.0.2.Final.jar,路径:hibernate-release-5.0.2.Final/lib/optional/proxool/hibernate-proxool-5.0.2.Final.jar

技术分享

最终,WEB-INF/lib下有这些jar包:

技术分享

(2)修改hibernate.cfg.xml:

<property name="hibernate.connection.provider_class">org.hibernate.proxool.internal.ProxoolConnectionProvider</property> 注意看,这里的路径变了。我这里的完整的hibernate.cfg.xml是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<session-factory>
		
		<property name="hibernate.proxool.pool_alias">ProxoolPool</property>
		<property name="hibernate.proxool.xml">proxool.xml</property>
		<property name="hibernate.connection.provider_class">org.hibernate.proxool.internal.ProxoolConnectionProvider</property>
		<property name="hibernate.proxool.existing_pool">true</property>

        
        <!-- SQL dialect -->
		<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
		<property name="show_sql">true</property>
		
		<mapping resource="com/hibtest1/entity/Users.hbm.xml" />
	</session-factory>
</hibernate-configuration>


四 测试:


技术分享

可以看出,已经很正常了,问题到此解决

本文出自 “zifangsky” 博客,请务必保留此出处http://983836259.blog.51cto.com/7311475/1712589

Unable to resolve name [org.hibernate.connection.ProxoolConnectionProvider] as strategy ...

标签:hibernate

原文地址:http://983836259.blog.51cto.com/7311475/1712589

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!