Springboot项目启动报错Failed to configure a DataSource: ‘url‘ attribute is not specified

        最近重新复习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
附项目结构:

在这里插入图片描述

这个有点坑,对于第一种,我也有点困惑,以前写springboot项目时,application.properties文件都是自动加载的,无需配置,现在不知道为什么要手动配置了,如果你遇见和我一样的问题,希望对你有所帮助。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值