意外输出java.lang.NoSuchMethodError:在构建项目时

时间:2017-10-31 11:30:11

标签: java mongodb gradle dependencies

问题

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

分析

1)我在各种线程中看到了commons数据与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')
}

@Edit

以下是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
  

任何人都可以通过提前看到stacktrace.Thankx来指导我

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]

1 个答案:

答案 0 :(得分:0)

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

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

Spring Data mongoDb

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

Spring Data commons

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