運行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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章