spring boot 整合mybatis时报错找不到数据库
1、问题
今天在使用springboot整合mybatis时发现报了一个很奇怪的错误。找不到数据库,报错信息如下:
Failed to configure a DataSource: ‘url’ attribute is not specified and
no embedded datasource could be configured.Reason: Failed to determine a suitable driver class
于是检查了一下application中的datasource配置,乍看之下并没有发现错误,配置信息如下:
datasource:
url: jdbc:mysql://localhost:3306/XX?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
2、解决问题
于是找度娘解决问题,百度大多是说在启动类修改注解,我的原注解如下图1所示修改为2之后依然报错,如下图所示,
报错:Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required。
还是数据库的配置问题,于是找出之前的项目仔细比对,发现application.yml配置错误,正确配置如下:然后再次启动
发现可以正常启动了…