***************************
APPLICATION FAILED TO START
***************************
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).
最近报了一个这样的错误,意思是没有提供数据库连接
可是我明明在application.yml配置文件中写了数据库的连接
server:
port: 8080
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/mydatabase?characterEncoding=utf8
username: root
password: 123
注意:如果你的数据库是8.0版本及以上的需要更改驱动和url
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mydatabase?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false
找了很久原来是pom.xml文件中没有写让他去找application.yml文件
所以需要在pom.xml文件的build标签中添加
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
注意:如果你的配置文件是以.properties文件名结尾的,需要将上述代码中的.yml更改成.properties