使用junit4测试的时候报错:Specified JDBC Driver class not found,请教各位大神,这该怎么弄

qq_36784082 2018-04-10 03:05:07
源码:
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();//关闭会话工厂
}
}


在获取session的时候报错
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!)
...全文
541 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yang_coder 2018-04-13
  • 打赏
  • 举报
回复
.ClassLoadingException你百度看看这种错误是什么解释。我也是小白,一般都是先看错误的类型
qq_36784082 2018-04-10
  • 打赏
  • 举报
回复
单纯启动项目的时候是没有问题的,只在junit测试的时候出现这个错误

50,451

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧