运行spring boot项目Failed to configure a DataSource

1.环境

win10
jdk13
Eclipse IDE for Enterprise Java Developers Version: 2019-12 (4.14.0)
apache-maven-3.6.3

2.创建springboot项目

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.配置/src/main/resources/application.properties文件

在这里插入图片描述

server.port=9001
#默认为server.port=8080

端口自定

4.创建controller

在这里插入图片描述

package com.example.demo.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
	@RequestMapping("/hello1")
	    public String sayHello() {
	        return "Hello, SpringBoot!";
	    }

}

3.运行报错

在这里插入图片描述
在这里插入图片描述


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


Action:

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

在这里插入图片描述

4.问题:

经过调试发现pom.xml文件加载:spring-boot-starter-jdbc,mysql-connector-java,但是application.properties文件没有相应的配置

5.解决方案:

1去掉spring-boot-starter-jdbc,mysql-connector-java

2.配置application.properties文件

在这里插入图片描述

6.重新运行

在这里插入图片描述
在这里插入图片描述
访问成功

发布了14 篇原创文章 · 获赞 0 · 访问量 6446
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章