求教!!junit4测试报错:org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver

在运行JUnit4测试时遇到了一个错误:org.hibernate.service.classloading.spi.ClassLoadingException,提示指定的JDBC驱动类未找到。错误源于Hibernate的DriverManagerConnectionProviderImpl尝试配置JDBC驱动时找不到相应的类。此问题可能导致进一步的NullPointerException,特别是在尝试获取数据库会话时。
摘要由CSDN通过智能技术生成
package test.com.rails.system.controller.manage;

import com.rails.system.dao.manage.impl.LeaderPersonDaoImpl;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;

/**
 * LeaderPersonDaoImpl Tester
 * Created by Administrator on 2018/4/10.
 */
public class LeaderPersonDaoImplTest {
    private static LeaderPersonDaoImpl leaderPersonDao = new LeaderPersonDaoImpl();
    public static SessionFactory sessionFactory = null;
    public static final Logger logger = LoggerFactory.getLogger(LeaderPersonDaoImpl.class);//日志
    private static Transaction transaction;
    private static Session session;
    @BeforeClass
    public static void runBeforeClass(){
        try {
            //创建配置对象
            Configuration config = new Configuration();
            //创建服务注册对象
            ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.configure().getProperties()).buildServiceRegistry();
            //创建会话工厂对象
            sessionFactory = config.buildSessionFactory(serviceRegistry);
            //sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
            //会话对象
            session = sessionFactory.openSession();
            //开启事务
            transaction = session.beginTransaction();

        } catch (HibernateException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testGetPersonList() throws Exception {
        HashMap map = new HashMap();
        map.put("userName", "周东伟");
        map.put("pageIndex", 1);
        map.put("pageSize", 15);
        Map m = leaderPersonDao.getPersonList(map);
        assertNotNull(m);
    }
    @AfterClass
    public static void afterClass() {
        transaction.commit();//提交事务
        session.close();//关闭会话
        sessionFactory.close();//关闭会话工厂
    }

}

报错:org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver  class not found at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:107) at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89) at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73) at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2283) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2279) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1748) at test.com.rails.system.controller.manage.LeaderPersonDaoImplTest.runBeforeClass(LeaderPersonDaoImplTest.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [2018-04-10 14:23:45]INFO  org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl(line:96) -HHH000402: Using Hibernate built-in connection pool (not for production use!) java.lang.NullPointerException at com.rails.system.dao.manage.impl.LeaderPersonDaoImpl.getSession(LeaderPersonDaoImpl.java:34) at com.rails.system.dao.manage.impl.LeaderPersonDaoImpl.getPersonList(LeaderPersonDaoImpl.java:90) at test.com.rails.system.controller.manage.LeaderPersonDaoImplTest.testGetPersonList(LeaderPersonDaoImplTest.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值