SpringBoot app can't connect to MariDB when connector version changed

Viewed 29

I have a SpringBoot application that worked nicely with MariaDB connector version 2.7.6. I tried to upgrade the connector to version 3.0.6 and it throws an error:

Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.RuntimeException: Driver org.mariadb.jdbc.Driver claims to not accept jdbcUrl, jdbc:mysql://localhost:3306/dbname

My application.properties are:

spring.datasource.url=jdbc:mysql://localhost:3306/dbname
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driverClassName=org.mariadb.jdbc.Driver

My Gradle dependencies are

dependencies {
    testImplementation 'junit:junit:4.13.2'
    testImplementation('org.junit.vintage:junit-vintage-engine'){
        exclude group: 'org.hamcrest', module:'hamcrest-core'
    }
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation ('org.springframework.boot:spring-boot-starter-test'){
        exclude group: "com.vaadin.external.google", module:"android-json"
    }
    implementation 'org.mariadb.jdbc:mariadb-java-client:2.7.6' // when 3.0.6 it is not working
    implementation 'org.json:json:20220320'
}

Any idea?

1 Answers

Since 3.0 MariaDB connector only accept jdbc:mariadb prefix by default:

It occurs that mysql AND mariadb driver are sometimes available in the same classpath, so, now, driver only accept jdbc:mariadb: by default.

If for some reason, connection string is required to be jdbc:mysql: Driver will be used only if connection string contain 'permitMysqlScheme'. example : jdbc:mysql:localhost/test?permitMysqlScheme.

see https://mariadb.com/kb/en/mariadb-connector-j-303-release-notes/#jdbcmariadb-scheme.

Related