请问关于SpringBoot和tk.mybaits整合启动失败的问题

[复制链接]
查看11 | 回复10 | 2021-1-27 05:27:04 | 显示全部楼层 |阅读模式
错误信息:
java.lang.IllegalStateException:FailedtoloadApplicationContext
Causedby:org.springframework.beans.factory.UnsatisfiedDependencyException:Errorcreatingbeanwithname'roleMapper'definedinfile[E:\projectCode\oa\target\classes\cn\oa\mapper\RoleMapper.class]:Unsatisfieddependencyexpressedthroughbeanproperty'sqlSessionFactory';nestedexceptionisorg.springframework.beans.factory.UnsatisfiedDependencyException:Errorcreatingbeanwithname'sqlSessionFactory'definedinclasspathresource[tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.class]:Unsatisfieddependencyexpressedthroughmethod'sqlSessionFactory'parameter0;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'dataSource'definedinclasspathresource[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:Beaninstantiationviafactorymethodfailed;nestedexceptionisorg.springframework.beans.BeanInstantiationException:Failedtoinstantiate[com.zaxxer.hikari.HikariDataSource]:Factorymethod'dataSource'threwexception;nestedexceptionisorg.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:Failedtodetermineasuitabledriverclass
Causedby:org.springframework.beans.factory.UnsatisfiedDependencyException:Errorcreatingbeanwithname'sqlSessionFactory'definedinclasspathresource[tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.class]:Unsatisfieddependencyexpressedthroughmethod'sqlSessionFactory'parameter0;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'dataSource'definedinclasspathresource[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:Beaninstantiationviafactorymethodfailed;nestedexceptionisorg.springframework.beans.BeanInstantiationException:Failedtoinstantiate[com.zaxxer.hikari.HikariDataSource]:Factorymethod'dataSource'threwexception;nestedexceptionisorg.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:Failedtodetermineasuitabledriverclass
Causedby:org.springframework.beans.BeanInstantiationException:Failedtoinstantiate[com.zaxxer.hikari.HikariDataSource]:Factorymethod'dataSource'threwexception;nestedexceptionisorg.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:Failedtodetermineasuitabledriverclass
Causedby:org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:Failedtodetermineasuitabledriverclass
spring启动类注解:
@SpringBootApplication
@MapperScan("cn.oa.mapper")
pom.xml配置:
UTF-8
UTF-8
1.8
2.1.5
8.0.19
2.1.2
1.18.12
1.5.4


org.springframework.boot
spring-boot-starter-web

org.springframework.boot
spring-boot-starter-test

mysql
mysql-connector-java
6.0.3
runtime

tk.mybatis
mapper-spring-boot-starter
${mapper.start.version}

org.projectlombok
lombok
${lombok.version}


分 -->
回复

使用道具 举报

千问 | 2021-1-27 05:27:04 | 显示全部楼层
配置文件加载失败?
回复

使用道具 举报

千问 | 2021-1-27 05:27:04 | 显示全部楼层
"Failedtodetermineasuitabledriverclass"配置文件里的数据库驱动配了吗
回复

使用道具 举报

千问 | 2021-1-27 05:27:04 | 显示全部楼层
配置文件名:application.yml
内容:
spring:
dataSource:
url:jdbc:mysql://localhost:3306/myoa
username:root
password:root
driver-class-name:com.mysql.jdbc.Driver
回复

使用道具 举报

千问 | 2021-1-27 05:27:04 | 显示全部楼层
用ProjectSourcesandDrivers测试可以连接数据库
回复

使用道具 举报

千问 | 2021-1-27 05:27:04 | 显示全部楼层
com.mysql.jdbc.Driver是mysql-connector-java5及5之前的,
com.mysql.cj.jdbc.Driver是mysql-connector-java6及6之后的的
回复

使用道具 举报

千问 | 2021-1-27 05:27:04 | 显示全部楼层
你看下是不是驱动版本不对

回复

使用道具 举报

千问 | 2021-1-27 05:27:04 | 显示全部楼层
引用6楼王博渊的回复:你看下是不是驱动版本不对
版本改过,还是不行
回复

使用道具 举报

千问 | 2021-1-27 05:27:04 | 显示全部楼层
还是不行是同一个原因吗?还是不一样的错误

回复

使用道具 举报

千问 | 2021-1-27 05:27:04 | 显示全部楼层
6以后的版本需要在后面加上时区
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql:///db1?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
username=root
password=root

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行