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.重新運行
訪問成功