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?
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
My annotation processing has suddenly stopped working. I've made no known changes to my configuration and haven't been able to find any references to the error I'm getting.
Gradle Version: 7.5.1
QueryDSL Version: 5.0.0
build.gradle:
implementation "com.querydsl:querydsl-core:${querydslVersion}"
implementation "com.querydsl:querydsl-jpa:${querydslVersion}"
implementation "com.querydsl:querydsl-apt:${querydslVersion}"
...
annotationProcessor ("javax.annotation:javax.annotation-api:1.3.2")
annotationProcessor ("org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final")
annotationProcessor ("com.querydsl:querydsl-apt:${querydslVersion}")
annotationProcessor ("com.querydsl:querydsl-apt:${querydslVersion}:jpa")
Error:
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':annotationProcessor'.
> Could not find querydsl-apt-5.0.0-jpa.jar (com.querydsl:querydsl-apt:5.0.0).
Searched in the following locations:
file:/Users/devuser/.m2/repository/com/querydsl/querydsl-apt/5.0.0/querydsl-apt-5.0.0-jpa.jar
Found a work around (9/24):
The version of querydsl-jpa is controlled by my JHipster BOM, which pulls in 5.0.0. But if I specify the 4.4.0 version in my annotation processor it works. So it seems like the behavior changed in 5.0.0, or the classifier needs to be specified in some other way. But this is how I got it to work again.
implementation group: 'com.querydsl', name:'querydsl-jpa', version:'+'
annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', classifier: 'jpa', version: '4.4.0'
i have newly added a below dependency into my project
implementation 'org.jdbi:jdbi3-oracle12:3.29.0'
these are the dependencies which i already have in my project.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.data:spring-data-jpa'
implementation 'org.hibernate:hibernate-core'
// Oracle JDBC drivers
implementation("com.oracle.database.jdbc:ojdbc11")
implementation("com.oracle.database.jdbc:ucp")
// Additional Jars for using Oracle Wallets
implementation("com.oracle.database.security:oraclepki")
implementation("com.oracle.database.security:osdt_core")
implementation("com.oracle.database.security:osdt_cert")
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.jdbi:jdbi3-core:3.28.0'
implementation 'org.jdbi:jdbi3-oracle12:3.29.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mockito:mockito-inline:4.5.1'
}
while adding the new dependency and doing gradle build. i'm getting the below error. can some one guide me how to fix this?
Execution failed for task ':compileJava'.
Could not resolve all files for configuration ':compileClasspath'.
Resolved 'org.jdbi:jdbi3-oracle12:3.29.0' which is not part of the dependency lock state
Resolved 'com.oracle.database.jdbc:ojdbc8:21.3.0.0' which is not part of the dependency lock state
I found a security vulnerability during the sonatype library scan in spring-beans and spring-context 5.2.12.Release version. But when I upgraded its parent library spring-webmvc to 5.3.14 to get rid of the vulnerability I got a new runtime error java.lang.NoSuchMethodError: org.springframework.web.cors.CorsConfiguration.addAllowedOriginPattern.
Resolved by upgrading spring-web and restricting it to a specific version
implementation (group: 'org.springframework', name: 'spring-web' ) {
version{
strictly '5.3.20'
}
}
I'm trying to get Mapstruct working with gradle. The implementations generate and work great when I run the service from the boot dashboard in eclipse, but they don't generate when run with gradlew bootrun, and the bean can't be found. Here is the error:
*************************** APPLICATION FAILED TO START
Description:
Field fooMapper in ServiceImpl required a bean of type 'FooMapper'
that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'FooMapper' in your configuration.
And here is my build.gradle file:
plugins {
id "org.springframework.boot"
id "groovy"
id "com.diffplug.eclipse.apt" version "3.31.0"
}
configurations {
// configuration to enable running bootRun locally
// with embedded h2 database
runlocal
}
ext {
mapstructVersion = "1.5.0.Beta1"
}
dependencies {
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testImplementation "org.testng:testng:6.10", "org.easytesting:fest-assert:1.4"
implementation project(":common")
implementation "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-jdbc:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-validation:$springBootVersion"
implementation "org.codehaus.gpars:gpars:1.2.1"
developmentOnly "org.springframework.boot:spring-boot-devtools:$springBootVersion"
runlocal project(":test-db")
testImplementation project(":test-db")
}
sourceSets.main.groovy.srcDirs += ["build/generated/sources"]
bootRun {
classpath = sourceSets.main.runtimeClasspath + configurations.runlocal
}
tasks.withType(JavaCompile) {
options.compilerArgs = [
"-Amapstruct.suppressGeneratorTimestamp=true",
"-Amapstruct.defaultComponentModel=spring",
"-Amapstruct.verbose=true"
]
}
Is it because my code is written in groovy? But then why would it work with the boot dashboard in eclipse? I am using #Mapper(componentModel = 'spring'), but that hasn't fixed the issue. Using version 1.4.2.FINAL also doesn't work. Any help would be really appreciated!
had the same problem in eclipse, solved configuring my project properties:
Go to:
Java Compiler > Annotation Processing
Set Enable Project specific settings to true
Go to:
Java Compiler > Annotation Processing > Factory Path
Add external jar:
Here find the location of your mapstruct-processor-1.4.2-Final.jar on the gradle cache directory, i am using debian 11, my path is on:
/.gradle/caches/modules-2/files-2.1/org.mapstruct/mapstruct-processor/1.4.2.Final/e55bd90d51cddd638c07d5bd89fc7535d4e3d069/mapstruct-processor-1.4.2.Final.jar
Apply and close, and gradle should rebuild the project, generating two new folders .apt_generated and .apt_generated_tests on the package explorer with the mapper code
I'm following along the 15 min guide for sprint-boot (gs-relational-data-access)
As such the guide works which uses H2-database.
So now I'm changing that to use DB2 by providing the jars at runtime.
Modified build.gradle
dependencies {
compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework:spring-jdbc")
runtime fileTree(dir: 'libs', include: '*.jar')
//compile("com.h2database:h2")
testCompile("junit:junit")
}
Now application fails complaining JdbcTemplate bean definitions not found or something along the lines.
So now I further modified the build.gradle to comment out the spring-jdbc, and use spring-boot-starter-jdbc
dependencies {
compile("org.springframework.boot:spring-boot-starter-jdbc")
//compile("org.springframework:spring-jdbc")
runtime fileTree(dir: 'libs', include: '*.jar')
//compile("com.h2database:h2")
testCompile("junit:junit")
}
Now the application works again. I'm interested in knowing why the spring-jdbc dependency didn't work with just the sprint-boot-starter?
spring-jdbc has all classes that spring support for JDBC API but spring-boot-starter-jdbc allow to enable all the auto-configuration needed. Thanks to the auto-configuration you can autowired JdbcTemplate and JdbcOperations with a simple configuration in application.properties