Spring Boot java.lang.IllegalArgumentException: URL must start with 'jdbc'

Viewed 1335

When trying to launch my project I get the error:

java.lang.IllegalArgumentException: URL must start with 'jdbc'

I configure my database connection in an application.properties file that looks like this:

spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}       

And have an maven/spring-boot start script that gets the VM options:

-DJDBC_DATABASE_URL="jdbc:postgresql://localhost:5432/project"
-DJDBC_DATABASE_USERNAME="postgres"
-DJDBC_DATABASE_PASSWORD="postgres"

A few tests showed me, that the VM options are completely not resolved but I have no idea on how to fix this.

My IDE is IntelliJ Community Edition.

It worked fine. Today I upgraded the project to Java 15 but in my opinion this should not result in such a problem.

Do you have any idea where the config gets overwritten or something?

1 Answers

When you quote just the value, the quote characters become part of the value, which means that the URL now starts with a "jdbc, so you get error saying "must start with jdbc".

You have two options:

  1. Don't quote:

    -DJDBC_DATABASE_URL=jdbc:postgresql://localhost:5432/project
    -DJDBC_DATABASE_USERNAME=postgres
    -DJDBC_DATABASE_PASSWORD=postgres
    
  2. Quote the whole argument:

    "-DJDBC_DATABASE_URL=jdbc:postgresql://localhost:5432/project"
    "-DJDBC_DATABASE_USERNAME=postgres"
    "-DJDBC_DATABASE_PASSWORD=postgres"
    
Related