Aplication.properties error when changing format

56 views Asked by At

I have:

spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=Europe/Madrid
spring.datasource.username=root
spring.datasource.password=secret

spring.jpa.hibernate.ddl-auto=update

and It works fine.

But when I try to do it this way:

spring:
    datasource:
        driverClassName: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/test?serverTimezone=Europe/Madrid
        username: root
        password: secret
    jpa:
        hibernate:
            ddl-auto: update

It fails with:

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

I assume it is a silly syntax error, but I can't notice where it is.

2

There are 2 answers

0
Carlos López Marí On BEST ANSWER

If you are going to use the YAML syntax, you need to specify it by changing the name of the file from application.properties to application.yml.

1
RUARO Thibault On

YML is very sensitive. Make sure you:

  • Use spaces instead of tabs
  • Use the proper extension: application.yml

See this: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-yaml