本文主要是介绍java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userController’: Unsatisfied dependency expressed through field ‘userService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userServiceImpl’: Unsatisfied dependency expressed through field ‘userMapper’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userMapper’ defined in file [C:\Users\Administrator\Desktop\tdkj\zljd\target\classes\com\tdkj\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method ‘sqlSessionFactory’ parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource’ defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Generic.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method ‘dataSource’ threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver
以上为原本报错信息,大意为 创建userService 时找到不到 名为userServiceImpl的依赖项 找不到名为UserMapper 的Bean 找不到dataSource 等 之后开始在 是否注入Bean方向开始找 发现 @Server @Mapper 等注解都没有问题,然后开始看最后一句 nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver 发现了问题 说是驱动有问题,
之后查看pom文件
看到用的版本是5.1.25 在上篇文章的配置文件中写到过 mysql 6以上的才需要将驱动配置改为com.mysql.cj.jdbc.Driver 6以下直接用 com.mysql.jdbc.Driver 即可
修改过后,Run起来啦
我会不定时记录一些日常工作遇到的问题,希望对你有所帮助
这篇关于java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!