关于Idea报java.lang.ClassNotFoundException: com.mysql.jdbc.Driver错误

在练习Thymeleaf配置页面时,Idea报出java.lang.ClassNotFoundException: com.mysql.jdbc.Driver的错误

异常信息如下:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at com.atguigu.myssm.basedao.BaseDAO.getConn(BaseDAO.java:43)
	at com.atguigu.myssm.basedao.BaseDAO.executeQuery(BaseDAO.java:192)
	at com.atguigu.fruit.dao.impl.FruitDAOImpl.getFruitList(FruitDAOImpl.java:12)
	at com.atguigu.fruit.servlets.IndexServlet.doGet(IndexServlet.java:23)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

 解决过程:

1.查找错误出现的原因

因为前一天晚上运行还成功,但是今天早上运行报错,首先排除了代码出现错误,其次我发现是我的项目模块依赖出现问题,昨天将桌面文件夹的目录从C盘移到了D盘,这样使得我的关于数据库MySQL和数据库连接池的驱动依赖位置改变

2.问题解决方式

重新添加模块依赖

关于Idea报java.lang.ClassNotFoundException: com.mysql.jdbc.Driver错误_第1张图片

关于Idea报java.lang.ClassNotFoundException: com.mysql.jdbc.Driver错误_第2张图片

最后再将存在的问题进行修复,即把所需的库添加到工件中。

程序重新启动后成功运行。

你可能感兴趣的:(java,intellij-idea,mysql)