java - 意外输出 java.lang.NoSuchMethodError : while building project

标签 java mongodb gradle dependencies

问题

我收到 java.lang.NoSuchMethodError: 错误,但我无法理解为什么...

分析

1)我在各种线程中看到公共(public)数据与 spring mongodb 的依赖关系不匹配,但在我的项目中找不到相同的情况。

2)下面是我的 gradle 依赖项...

对于api包--->build.gradle文件

buildscript {
ext {
    springBootVersion = '1.5.6.RELEASE'
}
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

springBoot {
executable = true
}

repositories {
mavenCentral()
}


dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
compile('org.springframework.boot:spring-boot-starter-data-redis')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile group: 'joda-time', name: 'joda-time', version: '2.9.9'
compile("io.springfox:springfox-swagger2:2.4.0")
compile("io.springfox:springfox-swagger-ui:2.4.0")
compile(group: 'net.sf.supercsv', name: 'super-csv', version: '2.4.0')
compile("com.fasterxml.jackson.datatype:jackson-datatype-joda:2.4.0")
compile project(":models")
compile project(":mongorepositories")
compile 'com.google.code.gson:gson:2.8.1'
compile "io.jsonwebtoken:jjwt:0.6.0"
compile('com.google.gms:google-services:3.1.0')
compile 'com.sendgrid:sendgrid-java:3.1.0'
compile("com.ganyo:gcm-server:1.0.2")
compile group: 'org.springframework.data', name: 'spring-data-commons-core', version: '1.3.2.RELEASE'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
compile group: 'org.springframework.data', name: 'spring-data-mongodb-parent', version: '1.10.6.RELEASE', ext: 'pom'
}

对于模型包 --->build.gradle 文件

buildscript {
ext {
    springBootVersion = '1.5.6.RELEASE'
}
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

jar {
baseName = 'models'
version =  '0.1.0'
}

repositories {
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile 'commons-validator:commons-validator:1.4.1'
compile group: 'joda-time', name: 'joda-time', version: '2.9.9'
compile ("com.fasterxml.jackson.core:jackson-annotations:2.8.4")
compile group: 'org.springframework.data', name: 'spring-data-mongodb-parent', version: '1.10.6.RELEASE', ext: 'pom'
compile group: 'org.springframework.data', name: 'spring-data-commons-core', version: '1.3.2.RELEASE'

}

task wrapper(type: Wrapper) {
gradleVersion = '2.11'
}

对于 mongorepository 包 --->build.gradle 文件

buildscript {
ext {
    springBootVersion = '1.5.6.RELEASE'
}
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'


sourceCompatibility = 1.8
repositories {
mavenCentral()
}


dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
compile('org.springframework.boot:spring-boot-starter-data-redis')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile group: 'joda-time', name: 'joda-time', version: '2.9.9'
compile project(":models")
compile group: 'org.springframework.data', name: 'spring-data-mongodb-parent', version: '1.10.6.RELEASE', ext: 'pom'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
}

@编辑

下面是 gradle 依赖项的输出

gradle dependencies
:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

No configurations

BUILD SUCCESSFUL

Total time: 28.042 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html

Can anyone guide me by seeing the stacktrace.Thankx in advance

java.lang.NoSuchMethodError: org.springframework.data.repository.core.support.AbstractRepositoryMetadata.getMetadata(Ljava/lang/Class;)Lorg/springframework/data/repository/core/RepositoryMetadata;    
at org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport.isStrictRepositoryCandidate(RepositoryConfigurationExtensionSupport.java:247) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport.getRepositoryConfigurations(RepositoryConfigurationExtensionSupport.java:94) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:123) ~[spring-data-commons-1.13.6.RELEASE.jar:na]
at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions(AbstractRepositoryConfigurationSourceSupport.java:59) ~[spring-boot-autoconfigure-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:359) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:143) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:320) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at com.ideationz.client.ConnectoApplication.main(ConnectoApplication.java:89) [classes/:na]

最佳答案

它已得到解决,因为 @veeram 和 @admit 建议配置正确的依赖项并删除重复依赖项的类路径。

我替换了项目中的 2 个依赖项,即

Spring Data mongoDb

compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: '1.10.6.RELEASE'

Spring Data 公共(public)

compile group: 'org.springframework.data', name: 'spring-data-commons', version: '1.13.6.RELEASE'

关于java - 意外输出 java.lang.NoSuchMethodError : while building project,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47034314/

相关文章:

mongodb - 如何计算匹配的数组元素

mongodb - 一个mongodb数组字段可以保存多少个BSON ObjectId

maven - 无法使用 Gradle 将 Artifact 发布到 Nexus maven 存储库

java - 如何在多 Gradle 项目的 JUnit Spring 上下文中加载资源属性?

java - 当我将我的 fragment 添加到我的 Activity 中时,我做错了什么?

java - 复制数组并使用 printall() 方法将其大小加 1 以返回新数组中的所有 int

java - 查找可能的 ServerSocket 列表

javascript - 为任何更新查询增加 Mongoose 文档版本的简单方法?

maven - 将Maven资源转换为Gradle资源

java - 在非常短的时间内在 Java 中搜索非常大的 ARPA 文件