使用SpringBoot找不到Mapper的Bean问题及解决
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版本就好了
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
给Java菜鸟的一些建议_关于Java知识点归纳(J2EE and Web 部分)
下面小编就为大家带来一篇给Java菜鸟的一些建议_关于Java知识点归纳(J2EE and Web 部分)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-05-05
springboot+springmvc+mybatis项目整合
这篇文章主要为大家详细介绍了springboot+springmvc+mybatis项目的整合,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2018-04-04
@JsonFormat 和 @DateTimeFormat 时间格式化注解(场景示例代码)
这篇文章主要介绍了@JsonFormat和@DateTimeFormat时间格式化注解,本文通过场景示例代码详解给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2023-05-05
SpringBoot使用Hibernate拦截器实现时间自动注入的操作代码
这篇文章主要介绍了SpringBoot使用Hibernate拦截器实现时间自动注入的操作代码,主要包括hibernate拦截器的相关知识,结合实例代码给大家讲解的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2022-10-10
@FeignClient注解中属性contextId的使用说明
这篇文章主要介绍了@FeignClient注解中属性contextId的使用说明,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-06-06


最新评论