Spring Boot DataSource: 'url' attribute is not specified
I am trying to follow this guide https://spring.io/guides/gs/accessing-data-mysql/
but this guide is for the maven and i am trying the gradle
and getting this error
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
in application.properties i have these things only.
spring.datasource.url=jdbc:mysql://localhost:3306/db_example spring.datasource.username=root spring.datasource.password=root spring.jpa.hibernate.ddl-auto=update spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
I tried all the possible things there is on the SO.
the only deps i have are these
dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' runtimeOnly 'mysql:mysql-connector-java' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } }
Or You will have to prevent Spring boot from automatically configuring the data source by adding this line to the file application.properties
.
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Check the target classpath directory. If the application.properties file didn’t exist, then delete the target and rebuild.
I would search the reason somewhere else.
Your error log tells you Reason: Failed to determine a suitable driver class
. Please build your project, and check if mysql driver is included in a built jar file. If jar is missing try to change your mysql dependency scope from runtimeOnly
to implementation
. The same problem can occur (at least I think so) if you try to run this project from IDE and solution should also help in that case.
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
error is unfortunately very generic and can happen in many different situations. For example last week I had received this error while using oracle Oracle when there where special signs in password which was specified in properties.yaml
without double-quotes.
Spring boot has chanegd the url to jdbc-url.
You need to use as below
spring.datasource.jdbc-url=jdbc:mysql://localhost:3306/db_example
Document Link: https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#data-properties