0

I have a working properties file for a Spring Boot application, but whenever I convert this into Yaml, I get an error, saying that the database url has not been specified.

I am using the following dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

and the config is as follows for the properties file (which works fine):

spring.datasource.url=jdbc:mysql://localhost:3306/db_name?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true

In Yaml I have:

 spring:
        datasource:
            url: "jdbc:mysql://localhost:3306/db_name?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"
            driver-class-name: com.mysql.cj.jdbc.Driver
            username: "username"
            password: "password"
        jpa:
            hibernate:
                ddl-auto: update
            generate-ddl: true
            show-sql: true

I have tried with and without quotation marks, I have tried driverClassName instead of driver-class-name, but each time I get the following message when the server tries to start up:

***************************
APPLICATION FAILED TO START
***************************

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
...
cadebe
  • 651
  • 1
  • 12
  • 35
  • 1
    Spacing of parameters can also effect, try changing them. It may help. And also as @fathy suggested removed quotes from value – Ravi Teja Oct 17 '19 at 12:35

3 Answers3

0

i think you have to remove " from

url: "jdbc:mysql://localhost:3306/db_name?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"

and make it like following

 url: jdbc:mysql://localhost:3306/db_name?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

and following link may help

fathy elshemy
  • 481
  • 5
  • 18
  • I researched a number of similar questions prior to posting the question here and decide to post it because I am totally stuck with this issue. Yes, I can leave it as it is, but for the option of having different active profile properties within a single file, I would like to have the Yaml version. As mentioned in the text, I have tried both with and without quotes before posting. I am wondering whether the URL somehow needs to be defined again, or that I may need to explicitly state mySQL as the database source. I have tried the yaml conversion a month ago and had exactly the same issues. – cadebe Oct 17 '19 at 13:38
  • you sure you put *** hibernate.dialect : org.hibernate.dialect.MySQLDialect *** – fathy elshemy Oct 17 '19 at 14:20
0

Do you have the MySql drive declared in your pom.xml file? If you do, Spring Boot should automatically pick up that you are using MySql and figure out the driver class.

Chris Savory
  • 2,597
  • 1
  • 17
  • 27
0

you just go to project , on the top, there is a clean all project is available then just clean everything after converting to yaml otherwise it won't detect yaml file. That's the solution and it worked for me also.