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.重新运行
访问成功