最近重新复习springboot技术时,新建了一个spingboot+mybatis+mysql的项目过程中,一直无法启动,报下面的错误,在网上搜的解决办法一直也没有解决我的问题,所以在此记录一下我的解决办法。
Description: 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
解决办法如下:
1、application.properties程序没有找到application.properties文件
这是我出现的问题
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
2、jar包冲突的缘故
删除掉jdbc的jar包
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
-->
在注解上加配置
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class })
备注:没解决我的问题
3、注意mysql的驱动版本
注意你自己的mysql-connector-java的版本
5.* 版本 spring.datasource.driver-class-name=com.mysql.jdbc.Driver
8.* 版本 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver