hibernate5配置Druid遇到Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.Con
程序员文章站
2022-04-12 20:59:46
...
今天开始学习hibernate框架,视频里用的是hibernate4,但我使用的是最新版的hibernate5.4,在配置Druid连接池时出现了以下错误
‘’’
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [com.alibaba.druid.support.hibernate.DruidConnectionProvider] as strategy [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:133)
at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:138)
at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:41)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
... 43 more
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.alibaba.druid.support.hibernate.DruidConnectionProvider]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:136)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:129)
... 47 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.alibaba.druid.support.hibernate.DruidConnectionProvider
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:210)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:133)
... 48 more
'''
在百度了网上很久都没有找到解决方式,突然想到会不会是版本不兼容,原先我的Druid使用的是1.0.9版本,
后来我试着调到了1.1.10版本,没想到成功了
所以是版本问题,升级你的Druid版本或者降低你的hibernate版本