Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
    }
}
like image 648
impressionableRepublic Avatar asked Nov 25 '22 23:11

impressionableRepublic


2 Answers

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

like image 119
Berthol Yvano Avatar answered Nov 29 '22 05:11

Berthol Yvano


This is kind of an old question but for anyone else coming across this, IF by any chance you are using IntelliJ (as OP does here based on his/her comments) make sure that our beloved IDE recognises your application.properties/application.yml as such by going to File -> Project Structure -> Modules then select your resources file and click on "Resources" from the Mark as: header thing (based on IntelliJ Community Edition 2019.1). Also keep in mind, as no doubt the IDE will certainly notify you, that by reimporting any Maven changes you will need to do this procedure again.

like image 22
shadysin Avatar answered Nov 29 '22 06:11

shadysin