Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/hibernate/service/jdbc/connections/spi/ConnectionProvider

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/hibernate/service/jdbc/connections/spi/ConnectionProvider

尝试将休眠版本 3.6.. 更新到 4.3. 时出现以下错误*

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/hibernate/service/jdbc/connections/spi/ConnectionProvider
java.lang.NoClassDefFoundError: org/hibernate/service/jdbc/connections/spi/ConnectionProvider
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access0(URLClassLoader.java:73)
    at java.net.URLClassLoader.run(URLClassLoader.java:368)
    at java.net.URLClassLoader.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:415)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:377)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:224)
    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:242)
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:125)
    at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:194)
    at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:120)
    at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:55)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:105)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)

我的 Hibernate Util class 是

private static SessionFactory buildSessionFactory() {
        try {
            SessionFactory sf = null;
            Configuration configuration = new Configuration().configure();
            //From the properties file
            serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
                    configuration.getProperties()).build();
            if (StringUtils.isNotBlank(Config.getHibernateConfigFile())) {
                ClassLoader loader = HibernateUtil.class.getClassLoader();
                if (loader == null)
                    loader = ClassLoader.getSystemClassLoader();

                java.net.URL configURL = loader.getResource(Config.getHibernateConfigFile());
                if (null != configURL) {
                    log.info("Configuring hibernate using " + Config.getHibernateConfigFile() + " located at " + configURL.toString());
//                 sf = new Configuration().configure(configURL).buildSessionFactory();
                    configuration = configuration.configure(configURL);
                    serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
                    sf = configuration.buildSessionFactory(serviceRegistry);

                } else
                    log.warn("Config file not found " + Config.getHibernateConfigFile());
            }
            //Default hibernate.cfg.xml from resource
            if (null == sf) {
                sf = configuration.buildSessionFactory(serviceRegistry);
            }
            return sf;
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            ex.printStackTrace();
            throw new ExceptionInInitializerError(ex);
        }
    }

我试了很多方法都找不到,有人能帮我吗:)

我的hibernate.cfg.xml

 <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/dummyDb?useLegacyDatetimeCode=false</property>
        <property name="connection.username">bobby</property>
        <property name="connection.password"></property>


        <!-- BonceCP connection pool -->
        <property name="hibernate.connection.provider_class">com.jolbox.bonecp.provider.BoneCPConnectionProvider
        </property>
        <property name="bonecp.setIdleMaxAgeInMinutes">60</property>
        <property name="bonecp.setIdleConnectionTestPeriodInMinutes">5</property>
        <property name="bonecp.partitionCount">3</property>
        <property name="bonecp.acquireIncrement">2</property>
        <property name="bonecp.maxConnectionsPerPartition">5</property>
        <property name="bonecp.minConnectionsPerPartition">2</property>
        <property name="bonecp.statementsCacheSize">50</property>
        <property name="bonecp.releaseHelperThreads">3</property>
        <property name="connection.autoReconnect">true</property>
        <property name="connection.autoReconnectForPools">true</property>
        <!--<property name="bonecp.idleConnectionTestPeriodInMinutes">60</property>-->
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

我的pom.xml是

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.9.Final</version>
        </dependency>
 <dependency>
            <groupId>com.jolbox</groupId>
            <artifactId>bonecp</artifactId>
            <version>0.8.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.jolbox</groupId>
            <artifactId>bonecp-provider</artifactId>
            <version>0.8.0-alpha1</version>
        </dependency>

Bonecp ConnectionProvider 的问题,Hibernate 4.3.9 需要来自包源的 Connection Provider,该包源已移动到 bonecp-0.8 中的另一个包。0.alpha 导致了问题

删除了 bonecp 并使用了 hibernate 4.3。* 默认支持 hikaricp

**注意:从 hikari 是 hibernate 4.3 的默认支持者*