坑2:就是我上面写的那一大堆错误,这个坑让我烦恼了一整天,茶不思饭不想。网上搜了很多答案,一点点排查,发现问题出在application.yml文件上。有一条语句: driver-class-name: com.mysql.jdbc.Driver。写了这句,启动服务后就会报出那一大堆恐怖的错误。但是错误虽多,最后一句都是 can not load driver class。试着删除这句,重启服务,成功了。但是这句不能删,删了还怎么读数据库?于是又开始网上搜,这回关键字就这一句。很快原因查到了,pom.xml文件中添加的依赖 mysql-connector-java 虽然导进去了,但lib库里这个包是空的!里面什么类都没有。什么原因我也不清楚,反正重新导了一次,这次弹出版本号了,选了最新的导进去,再启动服务,不再报错了。这时有种再世为人的感觉。不过很快下一个坑就又来了。
坑3:浏览器中输入接口地址localhost://8888/v1/getUserCount后,报“Host is not allowed to connect to this MySQL server” 百度后查到原因,是mysql不允许远程登录。我不明白我是本地访问怎么还成了远程登录了,不过解决方法很简单,修改mysql库里user表中localhost为‘%’后解决。于是迎来了最后一个坑。
坑4:解决上述所有问题后再次输入接口地址,回车,报“The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one” 莫名其妙出了个时区错误。好在这个错误网上的解决方法很多很简单,很快解决了。
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demo': Unsatisfied dependency expressed through field 'temp';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionTemplate' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0;
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$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 java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver