运行test的时候报错java.lang.ClassNotFoundException: Cannot find class:XXX
看了下这里是说我找不到

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jc.jdbc.Driver
### The error may exist in com/sandwich/dao/UserMapper.xml
### The error may involve com.sandwich.dao.UserDao.getUserList
### The error occurred while executing a query
### Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jc.jdbc.Driverat org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57)at com.sun.proxy.$Proxy4.getUserList(Unknown Source)at com.sandwich.dao.UserDaoTest.test(UserDaoTest.java:18)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:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jc.jdbc.Driverat org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:241)at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:220)at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:216)at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:95)at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:422)at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89)at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138)at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60)at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85)at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)... 28 moreProcess finished with exit code -1

有的时候应该细心看下控制台的信息,不应该直接复制错误去百度
我发现我这里不能用com.mysql.cj.jdbc.Driver,当然我这个错是敲错成jc了,但换成cj还是不对,这是mysql-connector-java问题,我后来看了博客对这个知识点又有了新的认识。最后改成com.mysql.jdbc.Driver就好
一般报这个错都是找不到类什么的,就要看自己是不是引入错了,可能是xml里属性用的不对,也有可能是像我这样的

修改后运行成功

java.lang.ClassNotFoundException: Cannot find class:相关推荐

  1. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法 java.lang.ClassNotFoundException: com.

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法 java.lang.ClassNotFoundException: com.m ...

  2. Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: org.springfra

    2019独角兽企业重金招聘Python工程师标准>>> 出现这个java.lang.ClassNotFoundException: org.springframework.web.c ...

  3. IDEA里运行代码时出现Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger的解决办法(图文详解)...

    问题详情 运行出现log4j的问题 "C:\Program Files\Java\jdk1.8.0_66\bin\java" -Didea.launcher.port=7533 & ...

  4. java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL

    转自:https://www.cnblogs.com/qianzf/p/7020613.html java.lang.ClassNotFoundException: org.springframewo ...

  5. java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL,spring获取context...

    今天学习spring项目的时候出现了下面的错误信息: java.lang.ClassNotFoundException: org.springframework.web.context.Context ...

  6. java.lang.ClassNotFoundException: org.codehaus.jackson.JsonProcessingException 异常解决方案

    在SpringMVC中使用Jackson实现json输出时配置如下: <!-- 输出对象转JSON支持 --> <bean id="stringConverter" ...

  7. jsf项目启动报:java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet

    java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet的错误,尝试了很多的很多的方法,也无疾而终. 解决方法: (1)   ...

  8. java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver

    1. 安装:SQL Server 2000 Driver for JDBC Service Pack 3 下载安装JDBC SP3 http://www.microsoft.com/downloads ...

  9. ShareEntryActivity java.lang.ClassNotFoundException | Android类找不到问题

    错误堆栈: Process: com.mci.smagazine, PID: 23265java.lang.RuntimeException: Unable to instantiate activi ...

  10. Struts2环境下Tomcat启动异常:Exception starting filter struts2,报了一个java.lang.ClassNotFoundException

    Struts2环境下Tomcat启动异常:Exception starting filter struts2,报了一个java.lang.ClassNotFoundException 参考文章: (1 ...

最新文章

  1. 石家庄地铁售票系统源码及截图(结对作业)
  2. 关于做Android+J2ee系统集成开发的一点心得
  3. 在Linux下安装Apache
  4. MySQL之alter和upate
  5. 八皇后问题的Java递归算法
  6. maven给默认中央仓库设置镜像为阿里云maven仓库并添加全局远程仓库
  7. CG-CTF-Web-/x00
  8. cryptico.js java解密_從Cryptico.js中提取RSA私鑰
  9. 西门子scl语言编程手册_西门子SCL编程PEEK指令讲解
  10. Mybatis_day4_Mybatis的延迟加载
  11. 域名转让代码_互联网域名转让协议(中英)
  12. 【优化算法】供需优化算法(SDO)【含Matlab源码 1804期】
  13. 考上985能改变命运吗_南开研究生称读研改变命运被嘲讽,网友:本科垃圾,考上985也没用...
  14. Android-Studio 缓存文件夹配置
  15. 新建网站的长尾词应该如何去做优化
  16. 小程序 | 如何清除手机上小程序缓存
  17. dos2unix 安装和使用
  18. 69. x 的平方根
  19. Mysql间隔时间查询数据
  20. 神经网络特征层可视化pytorch

热门文章

  1. 【c++数据结构】栈混洗的甄别算法
  2. 为企业出海“搭桥”,汇量科技靠什么出圈?
  3. 支持v4l2 linux内核选项 s3c2440,linux内核移植-移植2.6.35.4内核到s3c2440
  4. 梦幻西游服务器维修,《梦幻西游》电脑版2017年12月12日定期维护公告
  5. Workflow 在数据仓库建设中的应用与优化
  6. 服务器安全神器,Linux 上安装 Fail2Ban 保护 SSH
  7. 游戏动画中有哪些动画原理?
  8. java佳沃贴吧,十年沉淀 — 2019“JAVA(佳沃)杯”第十届凤凰山山地自行车挑战赛...
  9. 死磕YOLO系列,YOLOv1 的大脑、躯干和手脚
  10. 深度强化学习CS285-Lec18 Meta-Learning in RL