当前位置: 代码网 > it编程>编程语言>Java > 使用SpringBoot找不到Mapper的Bean问题及解决

使用SpringBoot找不到Mapper的Bean问题及解决

2026年04月26日 Java 我要评论
springboot找不到mapper的bean记一次令人抓狂的错误解决经历,先说结果:数据库版本使用错误,没有配置pom文件中的版本号,默认使用了本地驱动中的最高6版本。更改为5版本即可发生报错后找

springboot找不到mapper的bean

记一次令人抓狂的错误解决经历,先说结果:

数据库版本使用错误,没有配置pom文件中的版本号,默认使用了本地驱动中的最高6版本。

更改为5版本即可发生报错后找了很多的文档也没有符合我这个样子的,于是我就把自己的经历写下来,给和我一样犯了这个错的初学者看。

初期报错

@service
public class userservice {

    @autowired
    private deptmapper deptmapper;//此处报错为找不到mapper类型的bean
   

检查启动类中已经正确配置路径。

强行启动程序后

//这句话说使用数据库链接应该使用带cj那个,说明使用的驱动版本是6,但是编写的配置文件是5的配置。
loading class `com.mysql.jdbc.driver'. this is deprecated. the new driver class is `com.mysql.cj.jdbc.driver'. the driver is automatically registered via the spi and manual loading of the driver class is generally unnecessary.
//这句说的是找不到mapper的目录
property 'mapperlocations' was not specified.​

如果强行调用service

就会出现如下错误:

closing non transactional sqlsession [org.apache.ibatis.session.defaults.defaultsqlsession@6b3ac131]
2021-06-05 16:43:55.847 error 32732 --- [p-nio-80-exec-1] o.a.c.c.c.[.[.[/].[dispatcherservlet]    : servlet.service() for servlet [dispatcherservlet] in context with path [] threw exception [request processing failed; nested exception is org.mybatis.spring.mybatissystemexception: nested exception is org.apache.ibatis.exceptions.persistenceexception: 
### error querying database.  cause: org.springframework.jdbc.cannotgetjdbcconnectionexception: failed to obtain jdbc connection; nested exception is java.sql.sqlexception: the server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. you must configure either the server or jdbc driver (via the servertimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
### the error may exist in top/loveeveryone/mapper/deptmapper.java (best guess)
### the error may involve top.loveeveryone.mapper.deptmapper.selectbyprimarykey
### the error occurred while executing a query
### cause: org.springframework.jdbc.cannotgetjdbcconnectionexception: failed to obtain jdbc connection; nested exception is java.sql.sqlexception: the server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. you must configure either the server or jdbc driver (via the servertimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.] with root cause
//说数据库时区有问题

综合检查,发现数据库驱动有问题。

在pom文件中加载mysql数据库驱动程序时没有添加驱动程序版本,默认使用最高版本导致驱动失败。

将驱动修改至5版本就好了

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com