簡體   English   中英

啟動錯誤 spring 引導 - “嘗試調用不存在的方法”

[英]Error starting spring boot - "An attempt was made to call a method that does not exist"

我正在嘗試為我們的一個項目升級 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
        }
    }
}

internalToolAppServiceTierbuild.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'
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時,我得到一些 output,表明該應用程序能夠運行,但一段時間后,該應用程序失敗並且我在控制台中收到以下錯誤消息:

[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 帖子(錯誤啟動 spring 啟動“嘗試調用不存在的方法” )似乎表明存在重復的 package,我不太確定如何將其檢測為我對此很陌生。

誰能就我應該做什么提供解決方案或指導?


按照@Pritam Sadhukhan 的建議,我得到了同樣的錯誤,雖然略有不同,但它提到了相同 package 的不同版本導致問題


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

氖,

這是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')

這是全部嗎? 還是我錯過了什么

能否請您更改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'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM