启动 Spring Boot 时出错-“试图调用不存在的方法”

mi7gmzs6  于 2023-01-29  发布在  Spring
关注(0)|答案(2)|浏览(152)

我正在尝试为我们的一个项目升级Spring版本。
项目结构如下:

  • internalToolApp
  • internalToolAppServiceTier

2个子项目的包如下所示:
internalToolAppbuild.gradle

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.gradleinternalToolAppServiceTier

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
        }
    }
}

当我运行这个项目internalToolApp,我得到一些输出,显示应用程序能够运行,但一段时间后,应用程序失败&我在控制台中得到以下错误:

[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

我发现了一个类似的StackOverflow帖子[here](Error starting spring boot "An attempt was made to call a method that does not exist"),似乎表明有一个重复的包,我不太确定如何检测,因为我是新来的。
有人能提供解决方案或指导我应该怎么做吗?
按照@Pritam Sadhukhan的建议,我得到了相同的错误,虽然略有不同,但它提到了同一个包的不同版本导致的问题

***************************
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.7.2/f358e3f8ce01d3a26605fa23f9d3fd408726b033/spring-boot-autoconfigure-2.7.2.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.6.1/7db75a36248dad249eaa1a191f90c985cb9fff2f/mongodb-driver-core-4.6.1.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
hpcdzsge

hpcdzsge1#

代努姆
build.gradle应该是这个样子吗?

  1. jackson
    替换
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'
}

dependencies {
    compile('org.springframework.data:spring-boot-starter-json')
}
  1. mongo
    移除
compile("org.mongodb:mongo-java-driver:3.9.1") 
compile('org.springframework.data:spring-data-mongodb:3.2.0')

compile('org.springframework.data:spring-data-mongodb:3.2.0')
  1. spring-boot-starter-web
    替换
compile('org.springframework.boot:spring-boot-starter-web:2.6.9')

compile('org.springframework.boot:spring-boot-starter-web')

就这些吗?还是我错过了什么

x6h2sr28

x6h2sr282#

能否请您更改internalToolAppServiceTierbuild.gradle,并分别替换以下内容?

compile('org.springframework:spring-tx:5.3.21')

替换

compile('org.springframework.data:spring-data-mongodb:3.2.0')

implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.7.2'

相关问题