在使用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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值