I am trying to upgrade the Spring version for one of our projects.
The project structure is as listed below:
internalToolApp
internalToolAppServiceTier
The packages of the 2 sub-projects are listed below:
build.gradle
of internalToolApp
buildscript {
ext {
springBootVersion = '2.6.9'
}
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
dependencies {
classpath 'org.ajoberstar:grgit:1.7.2'
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
if (project.hasProperty("projVersion")) {
version = project.projVersion
} else {
version = "0.0-SNAPSHOT"
}
group = 'internalToolGroup'
// In this section you declare where to find the dependencies of your project
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
dependencies {
compile project(':internalToolAppServiceTier')
compile('org.springframework.boot:spring-boot-starter-web:2.6.9')
compile('com.github.ulisesbocchio:jasypt-spring-boot:2.1.0')
compile 'com.visa.commons.security.protectconfig:protectconfig-core:2.7.0'
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:3.1.4')
compile 'com.hazelcast:hazelcast-enterprise-all:4.2.1'
compile("com.hazelcast:hazelcast-spring:4.2.1")
compile("org.projectlombok:lombok:1.18.10")
compile('org.apache.tomcat:tomcat-jdbc:8.5.37')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0')
// Log4j 2
compile ('org.apache.logging.log4j:log4j-core:2.17.1')
compile ('org.apache.logging.log4j:log4j-api:2.17.1')
compile ('org.apache.logging.log4j:log4j-slf4j-impl:2.17.1')
compile ("commons-lang:commons-lang:2.6")
compile('org.apache.poi:poi:4.1.2')
compile('org.apache.poi:poi-ooxml:4.1.2')
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
bootJar {
exclude ("application.properties")
exclude ("database.properties")
exclude ("filetransfer.properties")
exclude ("mongo_local_application.properties")
}
task setupProject {
doFirst {
File dir = new File("$buildDir/../../../coreconfig_commons")
if(!dir.exists()) {
def grgit = org.ajoberstar.grgit.Grgit.clone(dir: "$buildDir/../../../anotherInternalTool", uri: "https://.....git")
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
build.gradle
of internalToolAppServiceTier
buildscript {
ext {
springBootVersion = '2.6.9'
}
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
dependencies {
classpath 'org.ajoberstar:grgit:1.7.2'
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'maven'
apply plugin: 'maven-publish'
if (project.hasProperty("projVersion")) {
version = project.projVersion
} else {
version = "0.0-SNAPSHOT"
}
group = 'internalToolGroup'
// In this section you declare where to find the dependencies of your project
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
configurations.all {
if (!project.hasProperty("local")) {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
dependencies {
if (project.hasProperty("local")) {
compile project(':CommonServiceTier')
compile project(':CommonUtility')
compile project(':CommonDBTier')
} else {
compile(group: 'internalToolGroup', name: 'CommonServiceTier', version: version){ changing = true }
compile(group: 'internalToolGroup', name: 'CommonUtility', version: version){ changing = true }
compile(group: 'internalToolGroup', name: 'CommonDBTier', version: version){ changing = true }
}
compile('org.springframework.boot:spring-boot-starter-web:2.6.9')
compile('org.springframework:spring-tx:5.0.12.RELEASE')
compile('com.github.ulisesbocchio:jasypt-spring-boot:2.1.0')
compile 'com.hazelcast:hazelcast-enterprise-all:4.2.1'
compile("com.hazelcast:hazelcast-spring:4.2.1")
compile("org.projectlombok:lombok:1.18.10")
compile("org.mongodb:mongo-java-driver:3.9.1")
compile('org.springframework.data:spring-data-mongodb:3.2.0')
compile 'com.fasterxml.jackson.core:jackson-core:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.4'
compile('org.mybatis:mybatis:3.5.0')
compile('org.mybatis:mybatis-spring:2.0.0')
compile 'org.apache.velocity:velocity:1.7'
compile 'org.apache.velocity.tools:velocity-tools-generic:3.0'
compile('org.apache.poi:poi:4.1.2')
compile('org.apache.poi:poi-ooxml:4.1.2')
compile('com.ibm.db2:db2jcc_license_cisuz:1.0')
compile('com.ibm.db2:db2java:1.0')
compile('com.ibm.db2:jcc:11.5.0.0')
// Log4j 2
compile ('org.apache.logging.log4j:log4j-core:2.17.1')
compile ('org.apache.logging.log4j:log4j-api:2.17.1')
compile ('org.apache.logging.log4j:log4j-slf4j-impl:2.17.1')
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
When I run this project internalToolApp
, i get some output, showing that the application is able to run, but after some time, the application fails & i get below error in the console:
[2023-01-26 16:59:55,238] [CompanyInternalTool] -- [...]- [main] WARN org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext [] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongo' threw exception; nested exception is java.lang.NoSuchMethodError: com.mongodb.MongoClientSettings$Builder.uuidRepresentation(Lorg/bson/UuidRepresentation;)Lcom/mongodb/MongoClientSettings$Builder;
Jan 26, 2023 4:59:55 PM com.hazelcast.core.LifecycleService
INFO: hz.client_1 [dev] [4.2.1] HazelcastClient 4.2.1 (20210630 - 6145014, 06a4018) is SHUTTING_DOWN
Jan 26, 2023 4:59:55 PM com.hazelcast.client.impl.connection.ClientConnectionManager
INFO: hz.client_1 [dev] [4.2.1] Removed connection to endpoint: [10.93.88.241]:5701:2c82e08d-47f2-44ef-a24e-d539a81aac35, connection: ClientConnection{alive=false, connectionId=1, channel=NioChannel{/127.0.0.1:55728->localhost/127.0.0.1:5701}, remoteAddress=[10.93.88.241]:5701, lastReadTime=2023-01-26 16:59:54.312, lastWriteTime=2023-01-26 16:59:54.283, closedTime=2023-01-26 16:59:55.241, connected server version=4.2.1}
Jan 26, 2023 4:59:55 PM com.hazelcast.core.LifecycleService
INFO: hz.client_1 [dev] [4.2.1] HazelcastClient 4.2.1 (20210630 - 6145014, 06a4018) is CLIENT_DISCONNECTED
Jan 26, 2023 4:59:55 PM com.hazelcast.core.LifecycleService
INFO: hz.client_1 [dev] [4.2.1] HazelcastClient 4.2.1 (20210630 - 6145014, 06a4018) is SHUTDOWN
Jan 26, 2023 4:59:55 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service [Tomcat]
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer.applyUuidRepresentation(MongoPropertiesClientSettingsBuilderCustomizer.java:67)
The following method did not exist:
com.mongodb.MongoClientSettings$Builder.uuidRepresentation(Lorg/bson/UuidRepresentation;)Lcom/mongodb/MongoClientSettings$Builder;
The calling method's class, org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer, is available from the following locations:
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.6.9/143e3b88bbf01a87d4877196c715e3b154d5e00c/spring-boot-autoconfigure-2.6.9.jar!/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.class
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.6.11/40e0e3011e8549b4591a0a3f26d21ba5978b6ed1/spring-boot-autoconfigure-2.6.11.jar!/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.class
The calling method's class was loaded from the following location:
file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.6.9/143e3b88bbf01a87d4877196c715e3b154d5e00c/spring-boot-autoconfigure-2.6.9.jar
The called method's class, com.mongodb.MongoClientSettings$Builder, is available from the following locations:
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.mongodb/mongo-java-driver/3.9.1/d313237180bf9f2f82e12f503d9617e6b070f792/mongo-java-driver-3.9.1.jar!/com/mongodb/MongoClientSettings$Builder.class
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.mongodb/mongodb-driver-core/4.2.3/ac8159055a465139c643355aa3af7f4c050bceb2/mongodb-driver-core-4.2.3.jar!/com/mongodb/MongoClientSettings$Builder.class
The called method's class hierarchy was loaded from the following locations:
com.mongodb.MongoClientSettings.Builder: file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.mongodb/mongo-java-driver/3.9.1/d313237180bf9f2f82e12f503d9617e6b070f792/mongo-java-driver-3.9.1.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer and com.mongodb.MongoClientSettings$Builder
I found a similar StackOverflow post [here](Error starting spring boot "An attempt was made to call a method that does not exist") that seems to indicate there is a duplicate package, I'm not quite sure how to detect that as I'm new to this.
Would anyone be able to provide a solution or guidance on what I should do?
CodePudding user response:
Deinum,
Is this what the build.gradle
should look like?
jackson
Replace
dependencies {
compile 'com.fasterxml.jackson.core:jackson-core:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.4'
}
with
dependencies {
compile('org.springframework.data:spring-boot-starter-json')
}
mongo
Remove
compile("org.mongodb:mongo-java-driver:3.9.1")
compile('org.springframework.data:spring-data-mongodb:3.2.0')
with
compile('org.springframework.data:spring-data-mongodb:3.2.0')
spring-boot-starter-web
Replace
compile('org.springframework.boot:spring-boot-starter-web:2.6.9')
with
compile('org.springframework.boot:spring-boot-starter-web')
Is this all? or did i miss something
CodePudding user response:
Can you please change the build.gradle
of internalToolAppServiceTier
and replace the following respectively?
compile('org.springframework:spring-tx:5.3.21')
Replace
compile('org.springframework.data:spring-data-mongodb:3.2.0')
to
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.7.2'