Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

Initialize the SpringBoot application and run the following error:

Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

Obviously, the application does not configure some related properties of datasource, such as database address, database driver, user name and password.

Therefore, you need to configure the following information in the application.properties :

#application-name
spring.application.name=demo

#port
server.port=7001

#encode
server.tomcat.uri-encoding=utf-8

#datasource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5

What I use here is com.mysql.jdbc.Driver drive, so the following packages need to be introduced into POM:

<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>5.1.25</version>
</dependency>

Run the application again after configuration.

Enjoy SpringBoot.

Add a Comment

Your email address will not be published.