一个很简单的bug 导致的程序不能运行
报错
ERROR 29836 — [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘ucenterMemberController’: Unsatisfied dependency expressed through field ‘memberService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘ucenterMemberServiceImpl’: Unsatisfied dependency expressed through field ‘baseMapper’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘ucenterMemberMapper’ defined in file [D:##java\java程序\online_education\service\service_ucenter\target\classes\com\atguigu\educenter\mapper\UcenterMemberMapper.class]: Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ‘sqlSessionFactory’ threw exception; nested exception is com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: GlobalConfigUtils setMetaData Fail ! Cause:com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Get proxy targetObject exception ! Cause:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘scopedTarget.dataSource’ defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method ‘dataSource’ threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
The last packet sent successfully to the server was 0 milliseconds ago
起因
昨天写的谷粒学院的程序,今天edu板块就不能运行了,起初以为是代码的问题,看了很多博客,各种解决办法都试过了,依赖都注入了。
1.mapper层是否加了@Mapper注解
2.在启动类上是否加了@MapperScan(“xxx.xxx.xxx.mapper”) 有其中一个就行
3.serviceImpl接口实现类是否有@Service注解
4.查看自己的api接口是否重名
用springboot框架,理论上只有application.properties,pom.xml,和xxxApplication中有用到注入mapper,检查了n遍,结果还是有问题。
运行其他程序,发现有部分可以运行,又找到之前版本的edu,发现还是不能运行。有怀疑是nacos的问题,终于折磨了半天,想着打开数据库看看,用Navicat打开,结果报错。
Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0
搞了半天,原来是数据库出问题了,总以为代码是不是有问题,结果最不会出问题的出问题了。
方法
在任务管理器中找到服务
把mysql服务重启,edu模块可以运行了。
教训
本来在有几个模块能运行的时候,就应该想到是不是数据库出了问题,因为能运行的模块都没有调用数据库。还是不够敏感,想着有问题就百度,没解决,就找关键词继续百度,光想着依靠别人来解决问题,没有自己先尝试着发现哪里有问题。最后还是靠的自己解决的。