我有一个毕业项目。我是 gradle 新手,并将我的一个项目转换为 gradle。我的项目正在运行,然后它开始让我出错。然后我注意到,如果我注释掉我的 Hibernate-entitymanger 依赖项,那么就没有错误。
这是我的 build.gradle 片段
apply plugin: 'application' // implicitly apply java and distribution plugin
apply plugin: 'eclipse'
apply plugin: 'project-report'
repositories {
mavenCentral()
mavenLocal()
}
ext {
//Spring
springFrameworkGroupId = "org.springframework"
springFrameworkVersion = "4.2.4.RELEASE"
springDataJpaVersion = "1.9.2.RELEASE"
//Hibernate
hibernateEntityManagerVersion = "5.1.0.Final"
hibernateValidatorVersion = "5.2.3.Final"
sqlJdbc4Version = "4.0"
....
}
dependencies {
compile group: log4jGroupId, name: 'log4j-api', version: log4jVersion
compile group: 'javax.el', name: 'javax.el-api', version: '3.0.0'
['spring-context-support', 'spring-jdbc', 'spring-oxm', 'spring-orm', 'spring-jms', 'spring-test'].each {
compile "$springFrameworkGroupId:$it:$springFrameworkVersion"
}
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: springDataJpaVersion
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: hibernateEntityManagerVersion
compile group: 'com.microsoft.sqlserver', name: 'sqljdbc4', version: sqlJdbc4Version
....
}
我只是在做
try (GenericApplicationContext springRootContext = new AnnotationConfigApplicationContext(RootContext.class)) { //error
BatchImportRequestService batchImportRequestService = springRootContext.getBean(BatchImportRequestServiceImpl.class);
batchImportRequestService.handleRequest(springRootContext, args);
} catch (Exception e) {
logger.error("Exception occurs in loading Spring root context: ", e);
}
当我这样做时,它给了我错误
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/basit.ahmed/.gradle/caches/modules-2/files-2.1/org.apache.activemq/activemq-all/5.13.0/4dc8405e5e52a05197e4e91d0e46b353107bcfe0/activemq-all-5.13.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/basit.ahmed/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.5/d1e34a4525e08873703fdaad6c6284f944f8ca8f/log4j-slf4j-impl-2.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.doWithLocalFields(Ljava/lang/Class;Lorg/springframework/util/ReflectionUtils$FieldCallback;)V
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:413)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:392)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:333)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:929)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
....
但是,如果注释掉我的hibernate-entitymaanger
依赖项,那么它就可以正常工作。喜欢
compile group: 'javax.el', name: 'javax.el-api', version: '3.0.0'
['spring-context-support', 'spring-jdbc', 'spring-oxm', 'spring-orm', 'spring-jms', 'spring-test'].each {
compile "$springFrameworkGroupId:$it:$springFrameworkVersion"
}
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: springDataJpaVersion
//compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: hibernateEntityManagerVersion
...
我还运行依赖树任务。这是我得到的
compile - Compile classpath for source set 'main'.
...
+--- org.springframework:spring-test:4.2.4.RELEASE
| \--- org.springframework:spring-core:4.2.4.RELEASE (*)
+--- org.springframework.data:spring-data-jpa:1.9.2.RELEASE
| +--- org.springframework.data:spring-data-commons:1.11.2.RELEASE
| | +--- org.springframework:spring-core:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| | +--- org.springframework:spring-beans:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| | +--- org.slf4j:slf4j-api:1.7.13
| | \--- org.slf4j:jcl-over-slf4j:1.7.13
| | \--- org.slf4j:slf4j-api:1.7.13
| +--- org.springframework:spring-orm:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-context:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-aop:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-tx:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-beans:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-core:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.aspectj:aspectjrt:1.8.7
| +--- org.slf4j:slf4j-api:1.7.13
| \--- org.slf4j:jcl-over-slf4j:1.7.13 (*)
+--- org.hibernate:hibernate-entitymanager:5.1.0.Final
| +--- org.jboss.logging:jboss-logging:3.3.0.Final
| +--- org.hibernate:hibernate-core:5.1.0.Final
| | +--- org.jboss.logging:jboss-logging:3.3.0.Final
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.javassist:javassist:3.20.0-GA
| | +--- antlr:antlr:2.7.7
| | +--- org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1
| | +--- org.jboss:jandex:2.0.0.Final
| | +--- com.fasterxml:classmate:1.3.0
| | +--- dom4j:dom4j:1.6.1
| | | \--- xml-apis:xml-apis:1.0.b2
| | \--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final
| | \--- org.jboss.logging:jboss-logging:3.3.0.Final
| +--- dom4j:dom4j:1.6.1 (*)
| +--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final (*)
| +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| +--- org.javassist:javassist:3.20.0-GA
| \--- org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1
+--- com.microsoft.sqlserver:sqljdbc4:4.0
default - 默认工件的配置。
+--- org.springframework.data:spring-data-jpa:1.9.2.RELEASE
| +--- org.springframework.data:spring-data-commons:1.11.2.RELEASE
| | +--- org.springframework:spring-core:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| | +--- org.springframework:spring-beans:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| | +--- org.slf4j:slf4j-api:1.7.13
| | \--- org.slf4j:jcl-over-slf4j:1.7.13
| | \--- org.slf4j:slf4j-api:1.7.13
| +--- org.springframework:spring-orm:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-context:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-aop:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-tx:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-beans:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-core:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.aspectj:aspectjrt:1.8.7
| +--- org.slf4j:slf4j-api:1.7.13
| \--- org.slf4j:jcl-over-slf4j:1.7.13 (*)
+--- org.hibernate:hibernate-entitymanager:5.1.0.Final
| +--- org.jboss.logging:jboss-logging:3.3.0.Final
| +--- org.hibernate:hibernate-core:5.1.0.Final
| | +--- org.jboss.logging:jboss-logging:3.3.0.Final
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.javassist:javassist:3.20.0-GA
| | +--- antlr:antlr:2.7.7
| | +--- org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1
| | +--- org.jboss:jandex:2.0.0.Final
| | +--- com.fasterxml:classmate:1.3.0
| | +--- dom4j:dom4j:1.6.1
| | | \--- xml-apis:xml-apis:1.0.b2
| | \--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final
| | \--- org.jboss.logging:jboss-logging:3.3.0.Final
| +--- dom4j:dom4j:1.6.1 (*)
| +--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final (*)
| +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| +--- org.javassist:javassist:3.20.0-GA
| \--- org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1
+--- com.microsoft.sqlserver:sqljdbc4:4.0
runtime - 源集“main”的运行时类路径。
+--- org.springframework.data:spring-data-jpa:1.9.2.RELEASE
| +--- org.springframework.data:spring-data-commons:1.11.2.RELEASE
| | +--- org.springframework:spring-core:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| | +--- org.springframework:spring-beans:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| | +--- org.slf4j:slf4j-api:1.7.13
| | \--- org.slf4j:jcl-over-slf4j:1.7.13
| | \--- org.slf4j:slf4j-api:1.7.13
| +--- org.springframework:spring-orm:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-context:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-aop:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-tx:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-beans:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.springframework:spring-core:4.1.9.RELEASE -> 4.2.4.RELEASE (*)
| +--- org.aspectj:aspectjrt:1.8.7
| +--- org.slf4j:slf4j-api:1.7.13
| \--- org.slf4j:jcl-over-slf4j:1.7.13 (*)
+--- org.hibernate:hibernate-entitymanager:5.1.0.Final
| +--- org.jboss.logging:jboss-logging:3.3.0.Final
| +--- org.hibernate:hibernate-core:5.1.0.Final
| | +--- org.jboss.logging:jboss-logging:3.3.0.Final
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.javassist:javassist:3.20.0-GA
| | +--- antlr:antlr:2.7.7
| | +--- org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1
| | +--- org.jboss:jandex:2.0.0.Final
| | +--- com.fasterxml:classmate:1.3.0
| | +--- dom4j:dom4j:1.6.1
| | | \--- xml-apis:xml-apis:1.0.b2
| | \--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final
| | \--- org.jboss.logging:jboss-logging:3.3.0.Final
| +--- dom4j:dom4j:1.6.1 (*)
| +--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final (*)
| +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| +--- org.javassist:javassist:3.20.0-GA
| \--- org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1
+--- com.microsoft.sqlserver:sqljdbc4:4.0
我该如何解决这个问题?为什么在包含的情况下我会出错Hibernate-entitymanger
?
谢谢